if (!isset($_POST["save"]) && !isset($_POST["upload"])) { HelperOperator::redirectTo("../views/profile_view.php"); } else { if (isset($_POST["save"])) { // Store POST values $update = ["username" => addslashes($_POST["username"]), "firstName" => addslashes($_POST["firstName"]), "lastName" => addslashes($_POST["lastName"]), "address" => addslashes($_POST["address"]), "postcode" => addslashes($_POST["postcode"]), "city" => addslashes($_POST["city"]), "country" => addslashes($_POST["country"])]; // Add empty string for default country if ($update["country"] == "Country") { $update["country"] = ""; } else { $update["country"] = QueryOperator::getCountryId($update["country"]); } // Get changed input fields (if available) $changedFields = ValidationOperator::getChangedFields($update); // Check inputs if (!empty($changedFields) && !ValidationOperator::hasEmtpyFields($update) && (!isset($changedFields["username"]) || !ValidationOperator::isTaken($update["username"]))) { // Update user information $user = SessionOperator::getUser(); QueryOperator::updateAccount($user->getUserId(), $update); // Update user session $user = QueryOperator::getAccount($user->getUserId()); SessionOperator::updateUser(new User($user)); // Set feedback session SessionOperator::setNotification(SessionOperator::UPDATED_PROFILE_INFO); } } else { $error = []; if (($upload = ValidationOperator::checkImage()) != null) { // A user is logged in if (!is_null($user = SessionOperator::getUser())) { // Create random image name
require_once "../classes/class.helper_operator.php"; require_once "../classes/class.session_operator.php"; require_once "../classes/class.validation_operator.php"; require_once "../classes/class.query_operator.php"; // Only process when sign up button was clicked if (!isset($_POST["signUp"])) { HelperOperator::redirectTo("../index.php"); } // Store POST values $registration = ["username" => $_POST["username"], "email" => $_POST["email"], "firstName" => $_POST["firstName"], "lastName" => $_POST["lastName"], "address" => $_POST["address"], "postcode" => $_POST["postcode"], "city" => $_POST["city"], "country" => $_POST["country"], "password1" => $_POST["password1"], "password2" => $_POST["password2"]]; // Add empty string for default country if ($registration["country"] == "Country") { $registration["country"] = ""; } // Check inputs if (ValidationOperator::hasEmtpyFields($registration) || ValidationOperator::isTaken($registration["username"], $registration["email"]) || !ValidationOperator::validPasswords($registration["password1"], $registration["password2"])) { // Create a session for all inputs so that they can be recovered after the page returns SessionOperator::setFormInput($registration); } else { // Create new user $registration["country"] = QueryOperator::getCountryId($registration["country"]); $encryptedPassword = password_hash($registration["password1"], PASSWORD_BCRYPT); $confirmCode = QueryOperator::addAccount(array($registration["username"], $registration["email"], $registration["firstName"], $registration["lastName"], $registration["address"], $registration["postcode"], $registration["city"], $registration["country"], $encryptedPassword)); // Create a session for the successfully submitted registration (account not verified yet) SessionOperator::setNotification(SessionOperator::SUBMITTED_REGISTRATION); // Email a verification link to the user - must be verified before accessing the new account require_once "../classes/class.email.php"; $mail = new Email($registration["email"], $registration["firstName"], $registration["lastName"]); $mail->prepareVerificationEmail($confirmCode); $mail->sentEmail(); }