Guest User

Untitled

a guest
Oct 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. public function loginAction()
  2.     {
  3.         $this->view->message = '';
  4.         $this->view->title = 'Log in';  
  5.  
  6.         if ($this->_request->isPost()) {
  7.            
  8.             // collect the data from the user
  9.             Zend_Loader::loadClass('Zend_Filter_StripTags');
  10.             $f = new Zend_Filter_StripTags();
  11.             $username = $f->filter($this->_request->getPost('usuarios_usuario'));
  12.             $password = $f->filter($this->_request->getPost('usuarios_senha'));
  13.            
  14.             //pr($this->_request->getPost());
  15.            
  16.             if (empty($username)) {
  17.                
  18.                 $this->view->message = 'Please provide a username.';
  19.                
  20.             } else {
  21.                
  22.                 // setup Zend_Auth adapter for a database table
  23.                 Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
  24.                 $db = Zend_Registry::get('db');
  25.                 $authAdapter = new Zend_Auth_Adapter_DbTable($db);
  26.                 $authAdapter->setTableName('usuarios');
  27.                 $authAdapter->setIdentityColumn('usuarios_usuario');
  28.                 $authAdapter->setCredentialColumn('usuarios_senha');
  29.                 // Set the input credential values to authenticate against
  30.                 $authAdapter->setIdentity($username);
  31.                 $authAdapter->setCredential($password);
  32.                 // do the authentication
  33.                 $auth = Zend_Auth::getInstance();
  34.                 $result = $auth->authenticate($authAdapter);
  35.                
  36.                 if ($result->isValid()) {
  37.                    
  38.                     // success: store database row to auth's storage
  39.                     // system. (Not the password though!)
  40.                     $data = $authAdapter->getResultRowObject(null,'password');
  41.                     $auth->getStorage()->write($data);
  42.                     $this->_redirect('/');
  43.                    
  44.                 } else {
  45.                    
  46.                     // failure: clear database row from session
  47.                     $this->view->message = 'Login failed.';
  48.                    
  49.                 }
  50.             }
  51.         }
  52.     }
Add Comment
Please, Sign In to add comment