authenticate.php 769 B

12345678910111213141516171819202122232425
  1. <?php
  2. session_start();
  3. require_once('models/User.php');
  4. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  5. $login = htmlspecialchars($_POST['login']);
  6. $passwd = htmlspecialchars($_POST['passwd']);
  7. try {
  8. $user = new User($login, $passwd);
  9. if (!$user->exists()) {
  10. header('Location: signin.php');
  11. $_SESSION['message'] = 'Bad password';
  12. exit();
  13. }
  14. $_SESSION['login'] = $login;
  15. header('Location: welcome.php');
  16. }
  17. catch(Exception $e) {
  18. $_SESSION['message'] = $e->getMessage();
  19. header('Location: signin.php');
  20. exit();
  21. }
  22. } else {
  23. header('Location: signin.php');
  24. }