Guest User

Untitled

a guest
Jul 23rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2.  
  3. class Admin_Plugin_AuthCheck extends Zend_Controller_Plugin_Abstract {
  4.  
  5. public function __construct() {
  6.  
  7. }
  8.  
  9. public function preDispatch(Zend_Controller_Request_Abstract $request) {
  10. $controller = $request->getControllerName();
  11. $action = $request->getActionName();
  12.  
  13. if($controller != 'auth') {
  14. $valid = Admin_Model_Authmanager::isLogedinAs('admin');
  15. if($valid == false) {
  16. $request->setControllerName('auth')
  17. ->setActionName('login');
  18. }
  19. }
  20. }
  21.  
  22. }
  23.  
  24.  
  25. ?>
  26.  
  27.  
  28. and the controller
  29.  
  30. <?php
  31.  
  32. <?php
  33.  
  34. class Admin_AuthController extends Zend_Controller_Action {
  35. public function init() {
  36. $this->_helper->layout->setLayout('admin');
  37. }
  38.  
  39. public function indexAction() {
  40. $valid = Admin_Model_Authmanager::isLogedinAs('admin');
  41. if($valid)
  42. $this->_redirect('/admin/');
  43. }
  44.  
  45. public function loginAction() {
  46.  
  47. $user = $this->getRequest()->getParam('user');
  48. $pass = $this->getRequest()->getParam('pass');
  49.  
  50. if($user == null || $pass == null)
  51. $this->_redirect('/admin/auth');
  52.  
  53. Admin_Model_Authmanager::login($user, $pass);
  54.  
  55. $valid = Admin_Model_Authmanager::isLogedinAs('admin');
  56. if($valid)
  57. $this->_redirect('/admin/');
  58. else
  59. $this->_forward('fail', 'auth', 'admin', array('user' => $user,
  60. 'pass' => $pass));
  61.  
  62. }
  63. public function logoutAction() {
  64. Admin_Model_Authmanager::logout();
  65. $this->_redirect('admin/');
  66. }
  67.  
  68. public function failAction() {
  69. $user = $this->getRequest()->getParam('user');
  70. $pass = $this->getRequest()->getParam('pass');
  71. $this->view->username = $user;
  72. $this->view->password = $pass;
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment