/** * Authentication method * * @return Zend_Auth_Result * @todo Db Col in code, use something like Admin_Model_DbRow_User, but this needs * to be rewritten to be in the App_ namespace */ public function authenticate() { $user = $this->adapter->request->getParam('username'); $pass = $this->adapter->request->getParam('passwort'); $salt = Zend_Registry::get('password_salt'); $internalAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter(), 'user_users', 'uu_username', 'uu_passwort', 'MD5(CONCAT(?, "' . $salt . '"))'); $result = $internalAdapter->setIdentity($user)->setCredential($pass)->authenticate(); if ($result->isValid()) { $this->adapter->getUser()->update((array) $internalAdapter->getResultRowObject()); } return new Zend_Auth_Result($result->getCode(), $this->adapter->getUser(), $result->getMessages()); }
/** * User login */ public function loginAction() { $this->_addHeadTitle("Login"); $this->_helper->layout()->setLayout("login"); $this->view->form = new Form_Login(); if ($this->getRequest()->isPost() && $this->view->form->isValid($this->_getAllParams())) { $adapter = new App_Auth_Adapter($this->_getParam('username'), $this->_getParam("password")); $result = $adapter->authenticate(); $result = Zend_Auth::getInstance()->authenticate($adapter); if (Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect('/index/index'); } else { $this->view->messages = $result->getMessages(); } } }
/** * Action to login a user * * @return Mixed * @access public */ public function loginAction() { $auth = Zend_Auth::getInstance(); $authAdapter = new App_Auth_Adapter($this->getRequest(), $this->getResponse()); $form = $authAdapter->getForm(); if ($this->getRequest()->isPost()) { $result = $auth->authenticate($authAdapter); if ($form->isValid($this->getRequest()->getParams()) && $result->isValid()) { $auth->getStorage()->write($authAdapter->getUser()); $this->_redirect('member/index'); } else { $form->setDescription('The credentials you provided are not valid. Please check your input'); } } $this->view->form = $form; return $this->render('login'); }