/** * loginAction * @author Thomas Schedler <*****@*****.**> */ public function loginAction() { $this->loadTheme(); $this->setTranslate(); $objAuth = Zend_Auth::getInstance(); if ($objAuth->hasIdentity()) { $this->_redirect($this->getRequest()->getParam('re', '/')); } else { $this->view->strErrMessage = ''; $this->view->strErrUsername = ''; $this->view->strErrPassword = ''; if ($this->_request->isPost()) { /** * data from the user * strip all HTML and PHP tags from the data */ $objFilter = new Zend_Filter_StripTags(); $username = $objFilter->filter($this->_request->getPost('username')); $password = md5($objFilter->filter($this->_request->getPost('password'))); if (empty($username)) { $this->view->strErrUsername = $this->core->translate->_('Please_enter_username'); } else { $this->core = Zend_Registry::get('Core'); /** * setup Zend_Auth for authentication */ if (ClientHelper::get('Authentication')->isActive() == true) { $objAuthAdapter = ClientHelper::get('Authentication')->getAdapter(); } else { $objAuthAdapter = new Zend_Auth_Adapter_DbTable($this->core->dbh); $objAuthAdapter->setTableName('users'); $objAuthAdapter->setIdentityColumn('username'); $objAuthAdapter->setCredentialColumn('password'); } /** * set the input credential values to authenticate against */ $objAuthAdapter->setIdentity($username); $objAuthAdapter->setCredential($password); /** * do the authentication */ $result = $objAuth->authenticate($objAuthAdapter); switch ($result->getCode()) { case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND: /** * do stuff for nonexistent identity */ $this->view->strErrUsername = $this->core->translate->_('Username_not_found'); break; case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID: /** * do stuff for invalid credential */ $this->view->strErrPassword = $this->core->translate->_('Wrong_password'); break; case Zend_Auth_Result::SUCCESS: if (ClientHelper::get('Authentication')->isActive() == true) { $objUserData = ClientHelper::get('Authentication')->getUserData(); $objUserRoleProvider = ClientHelper::get('Authentication')->getUserRoleProvider(); } else { /** * store database row to auth's storage system but not the password */ $objUserData = $objAuthAdapter->getResultRowObject(array('id', 'idLanguages', 'username', 'fname', 'sname')); $objUserData->languageId = $objUserData->idLanguages; unset($objUserData->idLanguages); $objUserRoleProvider = new RoleProvider(); $arrUserGroups = $this->getModelUsers()->getUserGroups($objUserData->id); if (count($arrUserGroups) > 0) { foreach ($arrUserGroups as $objUserGroup) { $objUserRoleProvider->addRole(new Zend_Acl_Role($objUserGroup->key), $objUserGroup->key); } } } $objSecurity = new Security(); $objSecurity->setRoleProvider($objUserRoleProvider); $objSecurity->buildAcl($this->getModelUsers()); Security::save($objSecurity); $objUserData->languageCode = null; $arrLanguages = $this->core->zooConfig->languages->language->toArray(); foreach ($arrLanguages as $arrLanguage) { if ($arrLanguage['id'] == $objUserData->languageId) { $objUserData->languageCode = $arrLanguage['code']; break; } } if ($objUserData->languageCode === null) { $objUserData->languageId = $this->core->zooConfig->languages->default->id; $objUserData->languageCode = $this->core->zooConfig->languages->default->code; } $objAuth->getStorage()->write($objUserData); $this->_redirect($this->getRequest()->getParam('re', '/')); break; default: /** * do stuff for other failure */ $this->view->strErrMessage = $this->core->translate->_('Login_failed'); break; } } } } $this->view->setScriptPath(GLOBAL_ROOT_PATH . 'public/website/themes/' . $this->objTheme->path . '/'); $this->renderScript('login.php'); }