1
0

home.php 931 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App;
  3. use RuntimeException;
  4. $core = Core::getInstance();
  5. $core->addBreadcrumb("/home", __("Log In"));
  6. $user = $core->getUser();
  7. if($user) {
  8. Http::redirect("/dashboard");
  9. }
  10. $request = Request::fromPost();
  11. $email = $request->email("email");
  12. $password = $request->raw("password");
  13. if($email) {
  14. try {
  15. $user = User::queryOne(["email" => $email]);
  16. if(!$user) {
  17. throw new RuntimeException(__("The credentials supplied do not match any records on the system."));
  18. }
  19. if(!$user->validatePassword($password)) {
  20. throw new RuntimeException(__("The credentials supplied do not match any records on the system."));
  21. }
  22. $_SESSION["user_id"] = $user->id;
  23. Session::addAlert("success", __("Logged in successfully."));
  24. Http::redirect("/dashboard");
  25. }
  26. catch(\Exception $e) {
  27. Session::addAlert("danger", $e->getMessage());
  28. }
  29. }
  30. View::include("header");
  31. View::include("home");
  32. View::include("footer");