Ejemplo n.º 1
0
 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;
 }