site.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class site extends Controller
  3. {
  4. public function index()
  5. {
  6. webApp::app()->requireLoginRedir();
  7. $this->titulo = '';
  8. $this->render('index');
  9. }
  10. public function login()
  11. {
  12. if (webApp::app()->isLoggedIn())
  13. header("Location: " . SITIO);
  14. else{
  15. if (isset($_POST["login"])) {
  16. $form = $this->constructLoginForm();
  17. $form->setAtributes($_POST['login']);
  18. if ($form->validate()) {
  19. $param = $form->getAtributes();
  20. if (webApp::app()->login($param["usuario"], $param["contrasena"])) {
  21. header("Location: " . SITIO);
  22. return;
  23. }
  24. }
  25. }
  26. $this->titulo = 'Iniciar sesión';
  27. $this->addCss(SITIO . 'assets/css/login.css');
  28. $this->render('login', array(
  29. 'loginForm' => $this->constructLoginForm()
  30. ));
  31. }
  32. }
  33. private function constructLoginForm()
  34. {
  35. return new webApp_form('login',
  36. array(
  37. new webApp_column(array(
  38. new webApp_input('usuario'),
  39. new webApp_password('contrasena', array(
  40. 'label' => 'Contraseña',
  41. ))
  42. ))
  43. ),
  44. array(
  45. 'buttons' => array(
  46. new webApp_button('login', webApp_button::SUBMIT, webApp_button::PRIMARY, array(
  47. 'label' => 'Iniciar sesión'
  48. ))
  49. )
  50. )
  51. );
  52. }
  53. public function logout()
  54. {
  55. webApp::app()->logout();
  56. header("Location: " . SITIO . 'site/login');
  57. }
  58. }