Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function loginAction()
- {
- $this->view->message = '';
- $this->view->title = 'Log in';
- if ($this->_request->isPost()) {
- // collect the data from the user
- Zend_Loader::loadClass('Zend_Filter_StripTags');
- $f = new Zend_Filter_StripTags();
- $username = $f->filter($this->_request->getPost('usuarios_usuario'));
- $password = $f->filter($this->_request->getPost('usuarios_senha'));
- //pr($this->_request->getPost());
- if (empty($username)) {
- $this->view->message = 'Please provide a username.';
- } else {
- // setup Zend_Auth adapter for a database table
- Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
- $db = Zend_Registry::get('db');
- $authAdapter = new Zend_Auth_Adapter_DbTable($db);
- $authAdapter->setTableName('usuarios');
- $authAdapter->setIdentityColumn('usuarios_usuario');
- $authAdapter->setCredentialColumn('usuarios_senha');
- // Set the input credential values to authenticate against
- $authAdapter->setIdentity($username);
- $authAdapter->setCredential($password);
- // do the authentication
- $auth = Zend_Auth::getInstance();
- $result = $auth->authenticate($authAdapter);
- if ($result->isValid()) {
- // success: store database row to auth's storage
- // system. (Not the password though!)
- $data = $authAdapter->getResultRowObject(null,'password');
- $auth->getStorage()->write($data);
- $this->_redirect('/');
- } else {
- // failure: clear database row from session
- $this->view->message = 'Login failed.';
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment