accountController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 adminAccountForm();
  13. if($form->wasSubmitted())
  14. {
  15. $form->addData($_POST);
  16. if($form->validate())
  17. {
  18. $password = $_POST['password'];
  19. $account = $_POST['username'];
  20. $auth = Staple_Auth::get();
  21. $granted = $auth->doAuth(array('username'=>$account,'password'=>$password));
  22. if($granted === true)
  23. {
  24. header('Location: '.$this->_link(array('index','index')));
  25. }
  26. else
  27. {
  28. $this->view->message = "Invalid login";
  29. $this->view->form = $form;
  30. }
  31. }
  32. else
  33. {
  34. $this->view->form = $form;
  35. }
  36. }
  37. else
  38. {
  39. $this->view->form = $form;
  40. }
  41. /*
  42. $form = new accountForm();
  43. if($form->wasSubmitted())
  44. {
  45. $form->addData($_POST);
  46. if($form->validate())
  47. {
  48. $pin = $_POST['pin'];
  49. $auth = Staple_Auth::get();
  50. $granted = $auth->doAuth(array('pin'=>$pin));
  51. if($granted === true)
  52. {
  53. header('Location: '.$this->_link(array('index','index')));
  54. }
  55. else
  56. {
  57. $this->view->message = "Invalid PIN";
  58. $this->view->form = $form;
  59. $this->layout->addScriptBlock('
  60. $(document).ready(function()
  61. {
  62. $(\'#errorMessage\').foundation(\'reveal\',\'open\');
  63. });
  64. ');
  65. }
  66. }
  67. else
  68. {
  69. $this->view->form = $form;
  70. }
  71. }
  72. else
  73. {
  74. $this->view->form = $form;
  75. }
  76. */
  77. }
  78. public function account()
  79. {
  80. echo Staple_Auth::get()->getAuthLevel();
  81. }
  82. public function admin()
  83. {
  84. $form = new adminAccountForm();
  85. if($form->wasSubmitted())
  86. {
  87. $form->addData($_POST);
  88. if($form->validate())
  89. {
  90. $password = $_POST['password'];
  91. $account = $_POST['username'];
  92. $auth = Staple_Auth::get();
  93. $granted = $auth->doAuth(array('username'=>$account,'password'=>$password));
  94. if($granted === true)
  95. {
  96. header('Location: '.$this->_link(array('timesheet','index')));
  97. }
  98. else
  99. {
  100. $this->view->message = "Invalid login";
  101. $this->view->form = $form;
  102. }
  103. }
  104. else
  105. {
  106. $this->view->form = $form;
  107. }
  108. }
  109. else
  110. {
  111. $this->view->form = $form;
  112. }
  113. }
  114. public function logout()
  115. {
  116. $auth = Staple_Auth::get();
  117. $auth->clearAuth();
  118. header('Location: '.$this->_link(array('account','index')));
  119. exit(0);
  120. }
  121. }
  122. ?>