Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class login
- {
- public function loginAction()
- {
- $this->view->message = '';
- $this->view->title = 'Log in';
- if (!$this->_request->isPost()) {
- $this->view->message = "favor prover os dados de login";
- return;
- }
- // collect the data from the user
- $filter = new Zend_Filter_StripTags();
- $username = $filter->filter(
- $this->_request->getPost('usuarios_usuario')
- );
- $password = $filter->filter(
- $this->_request->getPost('usuarios_senha')
- );
- if (empty($username)) {
- $this->view->message = 'Please provide a username.';
- return;
- }
- $authAdapter = new Zend_Auth_Adapter_DbTable(
- Zend_Db_Table::getDefaultAdapter()
- );
- $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()) {
- // failure: clear database row from session
- $this->view->message = 'Login failed.';
- return;
- }
- // success: store database row to auth's storage
- // system. (Not the password though!)
- $data = $authAdapter->getResultRowObject(null, 'password');
- $auth->getStorage()->write($data);
- $this->_redirect('/');
- }
- }
Add Comment
Please, Sign In to add comment