| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App;
- use RuntimeException;
- $core = Core::getInstance();
- $core->addBreadcrumb("/home", __("Log In"));
- $user = $core->getUser();
- if($user) {
- Http::redirect("/dashboard");
- }
- $request = Request::fromPost();
- $email = $request->email("email");
- $password = $request->raw("password");
- if($email) {
- try {
- $user = User::queryOne(["email" => $email]);
- if(!$user) {
- throw new RuntimeException(__("The credentials supplied do not match any records on the system."));
- }
- if(!$user->validatePassword($password)) {
- throw new RuntimeException(__("The credentials supplied do not match any records on the system."));
- }
- $_SESSION["user_id"] = $user->id;
- Session::addAlert("success", __("Logged in successfully."));
- HTTP::redirect("/dashboard");
- }
- catch(\Exception $e) {
- Session::addAlert("danger", $e->getMessage());
- }
- }
- View::include("header");
- View::include("home");
- View::include("footer");
|