|
|
@@ -0,0 +1,85 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+$page_title = "Reset Password";
|
|
|
+
|
|
|
+Core::addBreadcrumb("/reset-password", $page_title);
|
|
|
+
|
|
|
+if(!isset($token)) $token = false;
|
|
|
+
|
|
|
+if($token) {
|
|
|
+ $user = User::queryOne([
|
|
|
+ "reset_token" => $token
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$user) throw new Exception("Invalid reset token.");
|
|
|
+
|
|
|
+ $submit = http::value("submit");
|
|
|
+ if($submit) {
|
|
|
+ try {
|
|
|
+ Core::validateCSRFToken($submit);
|
|
|
+
|
|
|
+ $form_exception = new FormException;
|
|
|
+
|
|
|
+ $password = http::value("password");
|
|
|
+ $password_confirm = http::value("password_confirm");
|
|
|
+
|
|
|
+ if($password != $password_confirm) $form_exception->addError("Passwords do not match.");
|
|
|
+ if(!User::validatePassword($password)) $form_exception->addError("Password must be at least 6 characters in length and contain at least one lowercase, uppercase, number and special character.");
|
|
|
+
|
|
|
+ if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+
|
|
|
+ $user->password = password_hash($password, PASSWORD_DEFAULT, ["cost" => 14]);
|
|
|
+
|
|
|
+ $success = $user->commit();
|
|
|
+
|
|
|
+ Core::addAlert("success", "Password reset successfully. You can now log in.");
|
|
|
+ HTTP::redirect("/log-in");
|
|
|
+ }
|
|
|
+ catch(FormException $e) {
|
|
|
+ $e->generateAlerts();
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ Core::addAlert("danger", $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+else {
|
|
|
+ $submit = http::value("submit");
|
|
|
+ if($submit) {
|
|
|
+ try {
|
|
|
+ Core::validateCSRFToken($submit);
|
|
|
+
|
|
|
+ $form_exception = new FormException;
|
|
|
+
|
|
|
+ $email = http::value("email", "email");
|
|
|
+ if(!Form::checkRecaptcha()) $form_exception->addError("reCAPTCHA check failed.");
|
|
|
+ if(empty($email)) $form_exception->addError("Invalid email address.");
|
|
|
+ if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+
|
|
|
+ $user = User::queryOne(["email" => db::escape($email)]);
|
|
|
+ if($user) {
|
|
|
+ $user->sendPasswordResetEmail();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sleep(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ Core::addAlert("success", "A password reset email has been sent to the address provided if an account exists. Follow the instructions in the email to reset your password.");
|
|
|
+ HTTP::redirect("/log-in");
|
|
|
+ }
|
|
|
+ catch(FormException $e) {
|
|
|
+ $e->generateAlerts();
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ Core::addAlert("danger", $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+View::includeOnce("header", compact("page_title"));
|
|
|
+View::include("reset_password", compact("token"));
|
|
|
+View::includeOnce("footer");
|
|
|
+
|
|
|
+?>
|