Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class LoginController extends Zend_Controller_Action
- {
- public function init()
- {
- /* Initialize action controller here */
- }
- public function indexAction()
- {
- // action body
- }
- public function logoutAction()
- {
- Zend_Auth::getInstance()->clearIdentity();
- $this->_redirect('index/index');
- }
- public function loginAction()
- {
- if(Zend_Auth::getInstance()->hasIdentity())
- {
- $this->_redirect('index/index');
- }
- $form = new Application_Form_LoginForm();
- $this->view->form = $form;
- $this->view->blogTitle = 'Login blog';
- if($this->getRequest()->isPost())
- {
- $formData = $this->getRequest()->getPost();
- if($form->isValid($formData))
- {
- $username = $form->getValue('username');
- $password = $form->getValue('password');
- $authAdapter = $this->getAuthAdapter();
- $authAdapter->setIdentity($username)
- ->setCredential($password);
- $auth = Zend_Auth::getInstance();
- $result = $auth->authenticate($authAdapter);
- if($result->isValid())
- {
- //Store user identity information for use in the website.
- $identity = $authAdapter->getResultRowObject();
- $authstorage = $auth->getStorage();
- $authstorage->write($identity);
- $this->_redirect('index/index');
- }
- else
- {
- echo "invalid";
- }
- }
- }
- }
- protected function getAuthAdapter()
- {
- $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
- $authAdapter->setTableName('users')
- ->setIdentityColumn('username')
- ->setCredentialColumn('password');
- return $authAdapter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement