Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. require_once PATH . 'Models/UserModel.php';
  5. require_once PATH . 'Controllers/AbstractController.php';
  6.  
  7. class LoginController extends AbstractController {
  8. public function __construct() {
  9. parent::__construct();
  10. $this->model = new UserModel($this->db);
  11. }
  12. /*
  13. public function login() : string {
  14. if ($this->method === 'GET') {
  15. return $this->render('login.twig', []);
  16. }
  17.  
  18. $email = $_POST['email'] ?? '';
  19. $password = $_POST['password'] ?? '';
  20.  
  21. if (empty($email) || empty($email)) {
  22. return $this->render('login.twig', ['error' => "Please provide your email and password."]);
  23. }
  24.  
  25. $user = $this->model->getByEmail($email);
  26. if (isset($user) && password_verify($password, $user['password'])) {
  27. $_SESSION['userid'] = $user['id'];
  28. header('Location: index.php');
  29. }
  30. else {
  31. return $this->render('login.twig', ['error' => "Email and password did not match."]);
  32. }
  33. }
  34. */
  35. public function logout() : string {
  36. unset($_SESSION['user']);
  37. session_unset();
  38. session_destroy();
  39. return $this->render('login.twig', []);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement