login.php 1.0 KB

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