<?php session_start(); require 'UsersDatabase.php'; require 'helpers/adminManager.php'; if (isset($_SESSION['username']) && isAdmin($_SESSION['username'])) { $usersDatabase = new UsersDatabase('data/users.json'); $userData = array('username' => $_POST['username'], 'firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'password' => $_POST['password']); if ($usersDatabase->addNewUser($userData['username'], $userData['firstname'], $userData['lastname'], $userData['password'])) { echo "New user successfully added"; } else { echo "There was a problem adding new user"; } } else { echo "Unauthorized access"; }
<?php session_start(); require 'helpers/adminManager.php'; require 'PropertiesDatabase.php'; require 'UsersDatabase.php'; $error; if (isset($_SESSION['username']) && isAdmin($_SESSION['username'])) { $propertiesDatabase = new PropertiesDatabase('data/properties.json'); $usersDatabase = new UsersDatabase('data/users.json'); $allProperties = $propertiesDatabase->dataArray(); $soldProperties = $propertiesDatabase->soldProperties(); $unsoldProperties = $propertiesDatabase->unsoldProperties(); } else { // unauthorised accces $error = "You are not authorized to access this content, please login with an admin account."; } ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Sales Report</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1">
<?php require 'UsersDatabase.php'; session_start(); // Array to store login errors if they occur $loginerrors = isset($_SESSION['loginerrors']) ? $_SESSION['loginerrors'] : []; $fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : []; $usersData = new UsersDatabase('data/users.json'); if (isset($_SESSION['username'])) { $username = $_SESSION['username']; $name = $usersData->userFullName($username); } ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>100Acres - Login</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="css/font-awesome.min.css"> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/styles.css"> </head>
<?php require 'UsersDatabase.php'; session_start(); $users = new UsersDatabase('data/users.json'); // Array to store any possible arrays $errors = array(); $fields = array('username' => $_POST['username'], 'password' => $_POST['password']); // Collect all the errors if (empty($fields['username']) || empty($fields['password'])) { $errors[] = "Please fill in all the fields"; } else { if (!$users->userExists($fields['username'])) { $errors[] = "No such user found in the database"; } else { if (!$users->authenticationSucceeded($fields['username'], $fields['password'])) { $errors[] = "Wrong username and password combination"; } } } if (empty($errors)) { // If no errors occured $_SESSION['username'] = $fields['username']; } $_SESSION['loginerrors'] = $errors; $_SESSION['fields'] = $fields; header("Location: index.php");