Exemplo n.º 1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->structure = Doctrine::getTable('Structure')->createQuery('a')->fetchOne();
     sfContext::getInstance()->getUser()->setAttribute('relativeUrlRoot', $request->getRelativeUrlRoot());
     if ($request->isMethod(sfRequest::POST)) {
         /*$context=sfContext::getInstance();*/
         $login = $this->getRequestParameter('login');
         $password = $this->getRequestParameter('password');
         $usersAuth = new usersAuth();
         $checked = $usersAuth->verifyAuth($login, $password);
         //if the authentification is done
         if ($checked == 1 || $checked == 2) {
             ParametersConfiguration::setUserPrefix(sfContext::getInstance()->getUser()->getAttribute('login'));
             $loginDisplay = ParametersConfiguration::getDefault('default_follow_moderator');
             /*According to the 'default_follow_moderator' parameter, the login will appear in logs or not*/
             if ($loginDisplay == 1) {
                 $this->getContext()->get('Kernel')->addLog("info", "Authentification success for the login \"" . $login . "\".");
             } else {
                 $this->getContext()->get('Kernel')->addLog("info", "Authentification success.");
             }
             //Get the preferred culture of the user, based on those which are installed:
             $culture = ParametersConfiguration::getDefault('default_language');
             $this->getUser()->setCulture($culture);
             $request->setParameter('sf_culture', $culture);
             $this->redirect('@localized_homepage');
         } else {
             if ($checked === 0) {
                 // this delay complicates a brute force attack
                 sleep(1);
                 $this->getUser()->setFlash('error', 'Login or password incorrect. Please try again.', true);
                 $this->getContext()->get('Kernel')->addLog("error", "Authentification denied for the login \"" . $login . "\".");
             } else {
                 if ($checked === -2) {
                     $this->getUser()->setFlash('error', 'Login and password are correct but your account is locked.', true);
                     $this->getContext()->get('Kernel')->addLog("error", "Authentification denied for the login \"" . $login . "\". Account is locked.");
                 } else {
                     //The error message is copied in the error log
                     $this->getContext()->get('Kernel')->addLog("error", "Connection to the database failed:\"" . $checked . "\".");
                     $this->getUser()->setFlash('error', 'Impossible authentification. Check the connection to the database.', true);
                 }
             }
         }
     } else {
         $this->login = null;
         $this->password = null;
     }
 }