site.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. use oxusmedia\webAppMulti\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["email"], $param["contrasena"], $param["business"])) {
  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('business', array(
  45. 'label' => 'Agencia'
  46. )),
  47. new input('email'),
  48. new password('contrasena', array(
  49. 'label' => 'Contraseña',
  50. ))
  51. ))
  52. ),
  53. array(
  54. 'buttons' => array(
  55. new button('login', button::SUBMIT, button::PRIMARY, array(
  56. 'label' => 'Iniciar sesión'
  57. ))
  58. )
  59. )
  60. );
  61. }
  62. public function logout()
  63. {
  64. $this->webApp()->logout();
  65. $this->redirect($this->webApp()->getSite() . 'site/login');
  66. }
  67. }