site.php 2.0 KB

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