| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- $page_title = "Log In";
- Core::addBreadcrumb("/log-in", "Log In");
- $submit = http::value("submit");
- $csrf_token = $_SESSION["csrf_token"];
- if($submit) {
- try {
- Core::validateCSRFToken($submit);
- $email = http::value("email", "email");
- $password = http::value("password");
- if(empty($email)) throw new Exception("Email address is invalid.");
- if(empty($password)) throw new Exception("Password must be given.");
- $user = User::queryOne([
- "email" => db::escape($email)
- ]);
- if(!$user) throw new Exception("Account not found.");
- if(!password_verify($password, $user->password)) throw new Exception("Password is incorrect.");
- $_SESSION["user_id"] = $user->id;
- $redirect = $_SESSION["log_in_redirect_uri"] ?? "/account";
- Core::addAlert("success", "Log in successful.");
- HTTP::redirect($redirect);
- }
- catch(Exception $e) {
- Core::addAlert("danger", $e->getMessage());
- }
- }
- View::includeOnce("header", compact("page_title"));
- View::include("log_in");
- View::includeOnce("footer");
- ?>
|