login.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require_once('../templates/templates.php');
  3. $template = getTemplate('explorer_login.html');
  4. $context = ['errors' => '','post_url' => '../explorer/login.php'];
  5. function errorMessage () {
  6. global $context;
  7. $errorAlert = getTemplate('error_alert.html');
  8. $context['errors'] = parseTemplate($errorAlert, ['message'=>'Email ou senha incorretos. Certifique-se que os dados informados estão corretos']);
  9. }
  10. if (!empty($_POST)) {
  11. require_once('../controller/forms.php');
  12. require_once('../controller/validator.php');
  13. Validator::check(['email','senha'], $_POST);
  14. $email = Validator::email($_POST['email']);
  15. $password = Validator::str($_POST['senha']);
  16. try {
  17. $valid = checkFormAccess($email, $password);
  18. if ($valid) {
  19. session_start();
  20. $_SESSION['hash_user'] = $password;
  21. header('Location: index.php');
  22. exit;
  23. }
  24. errorMessage();
  25. } catch (Exception $e) {
  26. errorMessage();
  27. }
  28. }
  29. echo parseTemplate($template, $context);