Advertisement
Guest User

Untitled

a guest
May 4th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. class AuthenticationController extends Zend_Controller_Action
  4. {
  5.  
  6.     public function init()
  7.     {
  8.         /* Initialize action controller here */
  9.     }
  10.  
  11.     public function indexAction()
  12.     {
  13.         // action body
  14.     }
  15.  
  16.     public function loginAction()
  17.     {
  18.      $form = new getLoginForm();
  19.       $this->view->form = $form;
  20.       $authAdapter = $this->getAuthAdapter();
  21.      
  22.       $username = 'Lala';
  23.       $password = '912ec803b2ce49e4a541068d495ab570';
  24.        
  25.       $authAdapter->setIdentity($username)
  26.                ->setCredential($password);
  27.                
  28.       $auth = Zend_Auth::getInstance();
  29.       $result = $auth->authenticate($authAdapter);
  30.  
  31.       if($result -> isValid()){
  32.          $identity = $authAdapter->getResultRowObject();
  33.          
  34.          $authStorage = $auth->getStorage();
  35.          $authStorage->write($identity);
  36.          
  37.          $this->_redirect('index/index');
  38.       }else{
  39.           echo 'Invalid';        
  40.       }
  41.      
  42.       return $result;
  43.     }
  44.  
  45.     public function logoutAction()
  46.     {
  47.         // action body
  48.     }
  49.    
  50.     private function getAuthAdapter(){
  51.        
  52.         $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
  53.         $authAdapter->setTableName('users')
  54.                     ->setIdentityColumn('username')
  55.                     ->setCredentialColumn('password');
  56.         return $authAdapter;
  57.     }
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement