| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- $page_title = _("Log In");
- Core::addBreadcrumb("/log-in", $page_title);
- $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."));
- if(!$user->activated) {
- $user->sendActivationEmail();
- throw new Exception(_("Your email address is not verified. An activation email has been sent to your email address."));
- }
- $_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");
- ?>
|