Beispiel #1
0
 public function executeLogin($request)
 {
     $this->form = new LoginForm();
     $this->setLayout('identification_layout');
     if ($request->isMethod('post')) {
         try {
             $this->form->bind($request->getParameter('login'));
             if ($this->form->isValid()) {
                 $user = $this->getUser();
                 $params = $request->getParameter('login');
                 $id_role = TRolesTable::retrieve($params['login'])->getId_role();
                 $id_droit = TRolesTable::getDroitsUser($id_role);
                 if (array_key_exists($id_droit, TRolesTable::$credentials)) {
                     $credentials = TRolesTable::$credentials[$id_droit];
                     $user->addCredentials($credentials);
                     $user->setAuthenticated(true);
                     $user->setAttribute('login', $params['login']);
                     $this->redirect('@homepage');
                 }
             }
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
 }
Beispiel #2
0
 /**
  * Check login/pass
  *
  * @param sfValidator $validator
  * @param array $values
  * 
  * @return array
  */
 public function checkPassword($validator, $values)
 {
     $passmd5 = md5($values['password']);
     //la fonction identify est dans le fichier /lib/model/TRolesTable.class.php
     if (!empty($values['login']) && !empty($values['password']) && !TRolesTable::identify($values['login'], $passmd5)) {
         $error = new sfValidatorError($validator, 'Mot de passe incorrect');
         // throw an error bound to the password field
         throw new sfValidatorErrorSchema($validator, array('password' => $error));
     }
     return $values;
 }