/** * Get the local. Logic depends on whether the given controller is marked * as 'urlLocale' or not. * * @param Context $ctx * @param Controller $controller * @param String $lang the language from the URL, or null if it's not there. * @return String locale (language) */ private function getLocale($ctx, $controller, $lang) { // We only care here about controllers which are marked as 'urlLocale' if (!$controller->isLocaleSupported()) { return $ctx->getUser()->getLocale(); } if (!$lang) { $lang = $ctx->getUser()->getLocale(); } // Update anonymous user's locale, if it's different than the given lang if ($ctx->getUser()->isAnonymous() && $ctx->getUser()->getLocale() != $lang) { $ctx->getUser()->setLocale($lang); // TODO: does this code have to be here?? Zend_Session::setOptions(array('cookie_httponly' => 'on')); Zend_Session::RememberMe(1209600); // 14 days } return $lang; }
public function loginAction() { //if the user is logged already redir to home $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $this->_redirect('/' . $this->lang . '/woeid/' . $this->location . '/give'); } $request = $this->getRequest(); $form = $this->_getUserLoginForm(); if ($this->getRequest()->isPost()) { if ($form->isValid($request->getPost())) { $f = new Zend_Filter_StripTags(); $email = $f->filter($this->_request->getPost('email')); $password = $f->filter($this->_request->getPost('password')); //DDBB validation // setup Zend_Auth adapter for a database table $readConf = new Zend_Config_Ini(APPLICATION_PATH . '/config/nolotiro.ini', 'production'); $dbAdapter = Zend_Db::factory($readConf->resources->db); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('users'); $authAdapter->setIdentityColumn('email'); $authAdapter->setCredentialColumn('password'); // Set the input credential values to authenticate against $authAdapter->setIdentity($email); $authAdapter->setCredential(md5(trim($password))); //trim whitespaces from copy&pasting the pass from email // do the authentication $auth = Zend_Auth::getInstance(); //check first if the user is activated (by confirmed email) $select = $authAdapter->getDbSelect(); $select->where('active > 0'); //check if the user is not locked (spammers, bad users, etc) $select->where('locked = 0'); $result = $authAdapter->authenticate(); 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); $woeid = $this->_helper->CheckWoeidUser->checkUserLogged($auth->getIdentity()->id); $this->_helper->_flashMessenger->addMessage($this->view->translate('Welcome,') . ' ' . $auth->getIdentity()->username); Zend_Session::start(); //check if user wants to be remembered by 7 days $seconds = 60 * 60 * 24 * 7; if ($this->_request->getPost('rememberme') == "1") { Zend_Session::RememberMe($seconds); } else { Zend_Session::ForgetMe(); } //check the redir value if setted $aNamespace = new Zend_Session_Namespace('Nolotiro'); $redir = $aNamespace->redir; if ($redir !== null) { $aNamespace->redir = null; //reset redir value $this->_redirect($redir); } else { //if redir empty goto main home ads and set the welcome logged in message $this->_redirect('/' . $this->lang . '/woeid/' . $woeid . '/give'); } } else { // failure: wrong username $view = $this->initView(); $view->error = $this->view->translate('Wrong email or password, please try again'); } } } // assign the form to the view $this->view->form = $form; }