Advertisement
Guest User

Untitled

a guest
May 13th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. class LoginController extends Zend_Controller_Action
  4. {
  5.  
  6.     public function init()
  7.     {
  8.  
  9.         /* Initialize action controller here */
  10.     }
  11.  
  12.     public function indexAction()
  13.     {
  14.        
  15.         // action body
  16.     }
  17.  
  18.     public function logoutAction()
  19.     {
  20.         Zend_Auth::getInstance()->clearIdentity();
  21.         $this->_redirect('index/index');
  22.     }
  23.  
  24.     public function loginAction()
  25.     {
  26.         if(Zend_Auth::getInstance()->hasIdentity())
  27.         {
  28.             $this->_redirect('index/index');        
  29.         }
  30.            
  31.         $form = new Application_Form_LoginForm();
  32.         $this->view->form = $form;
  33.         $this->view->blogTitle = 'Login blog';  
  34.        
  35.         if($this->getRequest()->isPost())
  36.         {      
  37.             $formData = $this->getRequest()->getPost();
  38.             if($form->isValid($formData))
  39.             {
  40.                 $username = $form->getValue('username');
  41.                 $password = $form->getValue('password');
  42.                 $authAdapter = $this->getAuthAdapter();
  43.                 $authAdapter->setIdentity($username)
  44.                             ->setCredential($password);
  45.  
  46.                 $auth = Zend_Auth::getInstance();
  47.                 $result = $auth->authenticate($authAdapter);
  48.                 if($result->isValid())
  49.                 {
  50.                     //Store user identity information for use in the website.
  51.                     $identity = $authAdapter->getResultRowObject();
  52.                     $authstorage = $auth->getStorage();
  53.                     $authstorage->write($identity);
  54.                     $this->_redirect('index/index');
  55.                 }
  56.                 else
  57.                 {
  58.                     echo "invalid";
  59.                 }
  60.             }
  61.         }  
  62.  
  63.     }
  64.  
  65.     protected function getAuthAdapter()
  66.     {
  67.         $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
  68.         $authAdapter->setTableName('users')
  69.                     ->setIdentityColumn('username')
  70.                     ->setCredentialColumn('password');    
  71.         return $authAdapter;
  72.     }
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement