Exemplo n.º 1
0
 protected function doClean($values)
 {
     $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : '';
     bhLDAP::debug('######## Username: '******'password_field')]) ? $values[$this->getOption('password_field')] : '';
     bhLDAP::debug('######## User exists?');
     $user = Doctrine::getTable('sfGuardUser')->findOneByUsername($username);
     //    bhLDAP::debugDump($user, "user:");
     if (!$user) {
         if (bhLDAP::checkPassword($username, $password)) {
             // pretend the user exists, then check AD password
             bhLDAP::debug('######## User does not exist. Creating dummy user.');
             $user = new sfGuardUser();
             $user->setUsername($username);
             $user->setSalt('unused');
             $user->setPassword('unused');
             $user->setUserProfile(new UserProfile());
             $user->save();
         }
         return array_merge($values, array('user' => $user));
     }
     // password is ok?
     bhLDAP::debug('######## Checking Password...');
     if ($user->checkPassword($password)) {
         bhLDAP::debug('######## Check Password successful...');
         return array_merge($values, array('user' => $user));
     }
     bhLDAP::debug('######## Check Password failed...');
     if ($this->getOption('throw_global_error')) {
         throw new sfValidatorError($this, 'invalid');
     }
     throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
 }