LoginController.inc 790 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class LoginController implements IController {
  3. public function execute() {
  4. $form = new Form();
  5. $username = strtolower($form->post("username"));
  6. $password = $form->post("password");
  7. $authenticator = new Authenticator();
  8. $isLoggedIn = $authenticator->authenticate($username, $password);
  9. $view = new View();
  10. $loginData = array();
  11. $message = "";
  12. if ($isLoggedIn) {
  13. $user = new User();
  14. try {
  15. $user->populate();
  16. } catch (SessionExpiredException $e) {
  17. $message = "Session has expired.";
  18. }
  19. } else {
  20. $message = "Unable to authenticate user: perhaps the name or password is wrong?";
  21. }
  22. $location = "/";
  23. $header = new Header();
  24. if($message) {
  25. $location .= "?e=" . base64_encode($message);
  26. }
  27. $header->redirect($location);
  28. }
  29. }