public function loginAction() { $auth = $this->_getAuth(); if ($auth->hasIdentity()) { $this->_redirect($this->url('index'), array('exit' => true)); } $userLoginForm = new Application_Form_UserLogin(); /** @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); if ($request->isPost() && $userLoginForm->isValid($request->getPost())) { $authAdapter = $this->_getAuthAdapter(); $authAdapter->setIdentity($request->get('username')); $authAdapter->setCredential($request->get('password')); $authResult = $auth->authenticate($authAdapter); if (!$authResult->isValid()) { $messages = $authResult->getMessages(); foreach ($messages as $message) { $this->getFlashMessenger()->addErrorMessage($message, true); } } else { $this->getFlashMessenger()->addSuccessMessage('login successful'); $this->_redirect($this->url('index'), array('exit' => true)); } } $this->view->assign('form', $userLoginForm); }
public function loginAction() { $responseTime = rand(0, 1000000); if (!is_null($this->_session->getSessionId())) { if (!is_null($this->getParam('redirect'))) { $this->view->redirect = $this->getParam('redirect'); } else { $this->redirect('home/fead'); } } $this->_helper->layout->setLayout('entrance'); $request = $this->getRequest(); $form = new Application_Form_UserLogin(); if ($this->getRequest()->isPost()) { if ($form->isValid($request->getPost())) { $email = strtolower($form->getValue('email')); $user = $this->_userRepo->login($email, Application_Model_Hash::hash($form->getValue('password'))); // pending account if (is_null($user) && Application_Model_SignUpRepository::getInstance()->emailExists($email)) { $form->getElement('email')->addError($this->_translate->_('login_pending')); } else { if (is_null($user) || is_null($user->getEmail())) { $form->getElement('email')->addError($this->_translate->_('login_incorrect')); } else { if ($user->getRole() === 'deactivated') { $form->getElement('email')->addError($this->_translate->_('login_deactivated')); } else { if ($user->getRole() === 'guest') { $form->getElement('email')->addError($this->_translate->_('login_not_validated')); } else { $this->_session->setSessionId($user->getId()); usleep($responseTime); // redirect if (!is_null($form->getValue('redirect'))) { $this->redirect($form->getValue('redirect')); } $this->redirect('home/fead'); } } } } } } else { if ($this->getParam('redirect')) { $form->getElement('redirect')->setValue($this->getParam('redirect')); } } $this->view->form = $form; }
/** * Login action * * @return void */ public function loginAction() { if (Zend_Auth::getInstance()->hasIdentity()) { return $this->_helper->redirector('index', 'index'); } $request = $this->getRequest(); // Session expired? $authCookieName = Zend_Registry::get('config')->session->auth->name; if ($request->getCookie($authCookieName)) { // Remove/Expire auth cookie if (!Zend_Session::$_unitTestEnabled) { // @codeCoverageIgnoreStart $cookieParams = session_get_cookie_params(); setcookie($authCookieName, '', time() - 3600, $cookieParams['path'], $cookieParams['domain'], $cookieParams['secure'], true); } // @codeCoverageIgnoreEnd Logger::debug(__METHOD__ . ':: session has expired'); $this->view->messages()->addMessage('Your session has expired.', 'notice'); } $form = new \Application_Form_UserLogin(); // Process login request if ($request->isPost()) { if ($form->isValid($request->getPost()) && $this->_processAuth($form)) { // If user attempted to access page requiring authentication before // they were authenticated, then redirect them back to that page. $session = new Zend_Session_Namespace('referrer'); if (isset($session->uri)) { $uri = $session->uri; Zend_Session::namespaceUnset('referrer'); Logger::debug(__METHOD__ . ':: Post-login redirect to ' . $uri); return $this->getHelper('Redirector')->gotoUrl($uri); } // Otherwise, redirect to home page return $this->_helper->redirector('index', 'index'); } } $this->view->form = $form; }