SessionOperator::setNotification(SessionOperator::CHANGED_PASSWORD); // Send a password changed confirmation email to the user $mail = new Email($email, $userDetails["firstName"], $userDetails["lastName"]); $mail->preparePasswordConfirmEmail(); $mail->sentEmail(); HelperOperator::redirectTo("../index.php"); } else { SessionOperator::setFormInput($passwordFields); } HelperOperator::redirectTo("../views/change_password_view.php?email=" . $email); } else { if (isset($_POST["changePasswordSignedIn"])) { // Retrieve Passwords $passwordFields = ["currentPassword" => $_POST["currentPassword"], "password1" => $_POST["password1"], "password2" => $_POST["password2"]]; // Get current user session $user = SessionOperator::getUser(); // Current password is correct and both new passwords are valid and match if (!ValidationOperator::hasEmtpyFields($passwordFields) && ValidationOperator::isCurrentPassword($passwordFields["currentPassword"]) && ValidationOperator::validPasswords($passwordFields["password1"], $passwordFields["password2"])) { QueryOperator::updatePassword($user->getEmail(), $passwordFields["password2"]); SessionOperator::setNotification(SessionOperator::CHANGED_PASSWORD); // Send a password changed confirmation email to the user $mail = new Email($user->getEmail(), $user->getFirstName(), $user->getLastName()); $mail->preparePasswordConfirmEmail(); $mail->sentEmail(); } else { SessionOperator::setFormInput($passwordFields); } HelperOperator::redirectTo("../views/account_view.php"); } } }
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(); }