accountController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. class accountController extends Staple_AuthController
  3. {
  4. protected $Account;
  5. public function _start()
  6. {
  7. $this->_setLayout("account");
  8. $this->_openMethod('admin');
  9. }
  10. public function index()
  11. {
  12. $form = new accountForm();
  13. if($form->wasSubmitted())
  14. {
  15. $form->addData($_POST);
  16. if($form->validate())
  17. {
  18. $pin = $_POST['pin'];
  19. $auth = Staple_Auth::get();
  20. $granted = $auth->doAuth(array('pin'=>$pin));
  21. if($granted === true)
  22. {
  23. header('Location: '.$this->_link(array('index','index')));
  24. }
  25. else
  26. {
  27. $this->view->message = "Invalid PIN";
  28. $this->view->form = $form;
  29. $this->layout->addScriptBlock('
  30. $(document).ready(function()
  31. {
  32. $(\'#errorMessage\').foundation(\'reveal\',\'open\');
  33. });
  34. ');
  35. }
  36. }
  37. else
  38. {
  39. $this->view->form = $form;
  40. }
  41. }
  42. else
  43. {
  44. $this->view->form = $form;
  45. }
  46. }
  47. public function account()
  48. {
  49. echo Staple_Auth::get()->getAuthLevel();
  50. }
  51. public function admin()
  52. {
  53. $form = new adminAccountForm();
  54. if($form->wasSubmitted())
  55. {
  56. $form->addData($_POST);
  57. if($form->validate())
  58. {
  59. $password = $_POST['password'];
  60. $account = $_POST['username'];
  61. $auth = Staple_Auth::get();
  62. $granted = $auth->doAuth(array('username'=>$account,'password'=>$password));
  63. if($granted === true)
  64. {
  65. header('Location: '.$this->_link(array('timesheet','index')));
  66. }
  67. else
  68. {
  69. $this->view->message = "Invalid login";
  70. $this->view->form = $form;
  71. }
  72. }
  73. else
  74. {
  75. $this->view->form = $form;
  76. }
  77. }
  78. else
  79. {
  80. $this->view->form = $form;
  81. }
  82. }
  83. public function logout()
  84. {
  85. $auth = Staple_Auth::get();
  86. $auth->clearAuth();
  87. header('Location: '.$this->_link(array('account','index')));
  88. exit(0);
  89. }
  90. }
  91. ?>