Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Admin_Plugin_AuthCheck extends Zend_Controller_Plugin_Abstract {
- public function __construct() {
- }
- public function preDispatch(Zend_Controller_Request_Abstract $request) {
- $controller = $request->getControllerName();
- $action = $request->getActionName();
- if($controller != 'auth') {
- $valid = Admin_Model_Authmanager::isLogedinAs('admin');
- if($valid == false) {
- $request->setControllerName('auth')
- ->setActionName('login');
- }
- }
- }
- }
- ?>
- and the controller
- <?php
- <?php
- class Admin_AuthController extends Zend_Controller_Action {
- public function init() {
- $this->_helper->layout->setLayout('admin');
- }
- public function indexAction() {
- $valid = Admin_Model_Authmanager::isLogedinAs('admin');
- if($valid)
- $this->_redirect('/admin/');
- }
- public function loginAction() {
- $user = $this->getRequest()->getParam('user');
- $pass = $this->getRequest()->getParam('pass');
- if($user == null || $pass == null)
- $this->_redirect('/admin/auth');
- Admin_Model_Authmanager::login($user, $pass);
- $valid = Admin_Model_Authmanager::isLogedinAs('admin');
- if($valid)
- $this->_redirect('/admin/');
- else
- $this->_forward('fail', 'auth', 'admin', array('user' => $user,
- 'pass' => $pass));
- }
- public function logoutAction() {
- Admin_Model_Authmanager::logout();
- $this->_redirect('admin/');
- }
- public function failAction() {
- $user = $this->getRequest()->getParam('user');
- $pass = $this->getRequest()->getParam('pass');
- $this->view->username = $user;
- $this->view->password = $pass;
- }
- }
Add Comment
Please, Sign In to add comment