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.73 KB | None | 0 0
  1. <?php
  2.  
  3. class login
  4. {
  5.  
  6.     public function loginAction()
  7.     {
  8.         $this->view->message = '';
  9.         $this->view->title = 'Log in';
  10.  
  11.         if (!$this->_request->isPost()) {
  12.             $this->view->message = "favor prover os dados de login";
  13.             return;
  14.         }
  15.            
  16.         // collect the data from the user
  17.         $filter = new Zend_Filter_StripTags();
  18.         $username = $filter->filter(
  19.             $this->_request->getPost('usuarios_usuario')
  20.         );
  21.         $password = $filter->filter(
  22.             $this->_request->getPost('usuarios_senha')
  23.         );
  24.  
  25.         if (empty($username)) {
  26.             $this->view->message = 'Please provide a username.';
  27.             return;
  28.         }
  29.  
  30.         $authAdapter = new Zend_Auth_Adapter_DbTable(
  31.             Zend_Db_Table::getDefaultAdapter()
  32.         );
  33.  
  34.         $authAdapter->setTableName('usuarios');
  35.         $authAdapter->setIdentityColumn('usuarios_usuario');
  36.         $authAdapter->setCredentialColumn('usuarios_senha');
  37.         // Set the input credential values to authenticate against
  38.         $authAdapter->setIdentity($username);
  39.         $authAdapter->setCredential($password);
  40.         // do the authentication
  41.         $auth = Zend_Auth::getInstance();
  42.         $result = $auth->authenticate($authAdapter);
  43.  
  44.         if (!$result->isValid()) {
  45.             // failure: clear database row from session
  46.             $this->view->message = 'Login failed.';
  47.             return;
  48.         }
  49.  
  50.         // success: store database row to auth's storage
  51.         // system. (Not the password though!)
  52.         $data = $authAdapter->getResultRowObject(null, 'password');
  53.         $auth->getStorage()->write($data);
  54.         $this->_redirect('/');
  55.     }
  56.  
  57. }
Add Comment
Please, Sign In to add comment