addOption('username_field', 'email'); $this->addOption('password_field', 'password'); $this->addMessage('empty', 'Email is mandatory'); $this->addMessage('notfound', 'This email is not registered'); $this->addMessage('deleted', 'Your account is deleted'); $this->addMessage('wrongpass', 'Password is incorrect'); $this->addMessage('confirmemail', 'Your email needs to be confirmed'); } protected function doClean($values) { $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : ''; $password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : ''; // don't allow to sign in with an empty username if($username) { $user = Doctrine::getTable('User')->findOneBy('email', $username); if($user) { if(!$user->isDeleted()) { if(!$user->hasConfirmedEmail()) { throw new sfValidatorError($this, 'confirmemail'); } else { if($user->getPassword() == $password) { return array_merge($values, array('user' => $user)); } else { throw new sfValidatorError($this, 'wrongpass'); } } } else { throw new sfValidatorError($this, 'deleted'); } } else { throw new sfValidatorError($this, 'notfound'); } } else { throw new sfValidatorError($this, 'empty'); } } }