log_in.php 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. $page_title = "Log In";
  3. Core::addBreadcrumb("/log-in", "Log In");
  4. $submit = http::value("submit");
  5. $csrf_token = $_SESSION["csrf_token"];
  6. if($submit) {
  7. try {
  8. Core::validateCSRFToken($submit);
  9. $email = http::value("email", "email");
  10. $password = http::value("password");
  11. if(empty($email)) throw new Exception("Email address is invalid.");
  12. if(empty($password)) throw new Exception("Password must be given.");
  13. $user = User::queryOne([
  14. "email" => db::escape($email)
  15. ]);
  16. if(!$user) throw new Exception("Account not found.");
  17. if(!password_verify($password, $user->password)) throw new Exception("Password is incorrect.");
  18. $_SESSION["user_id"] = $user->id;
  19. Core::addAlert("success", "Log in successful.");
  20. HTTP::redirect("/account");
  21. }
  22. catch(Exception $e) {
  23. Core::addAlert("danger", $e->getMessage());
  24. }
  25. }
  26. View::includeOnce("header", compact("page_title"));
  27. View::include("log_in");
  28. View::includeOnce("footer");
  29. ?>