public function configure() { $this->setWidgets(array('password' => new sfWidgetFormInputPassword(array(), array('size' => 30)), 'password1' => new sfWidgetFormInputPassword(array(), array('size' => 30)), 'password2' => new sfWidgetFormInputPassword(array(), array('size' => 30)))); $this->setValidators(array('password' => new sfValidatorString(array('required' => true)), 'password1' => new sfValidatorRegex(array('pattern' => '/^[a-z0-9]{6,20}$/i')), 'password2' => new sfValidatorString(array(), array('required' => 'You must enter the password twice')))); $postValidator = new sfGuardValidatorUser(); $postValidator->setMessage('invalid', 'Your current password does not match the one you entered.'); $postValidator->addOption('throw_global_error', true); $this->validatorSchema->setPostValidator($postValidator); $this->widgetSchema->setLabels(array('password' => 'Current password', 'password1' => 'New password', 'password2' => '(again)')); $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password1', sfValidatorSchemaCompare::EQUAL, 'password2'), array(), array('invalid' => 'You must enter the same password twice')); $this->validatorSchema->setOption('allow_extra_fields', true); $this->validatorSchema->setOption('filter_extra_fields', false); $this->widgetSchema->setNameFormat('change_password[%s]'); }
public function configure() { $this->setWidgets(array('username' => new sfWidgetFormInput(array(), array('size' => 40)), 'password' => new sfWidgetFormInput(array('type' => 'password'), array('size' => 40)), 'remember' => new sfWidgetFormInputCheckbox())); $this->setValidators(array('username' => new sfValidatorString(), 'password' => new sfValidatorString())); $postValidator = new sfGuardValidatorUser(); $postValidator->setMessage('invalid', 'The email and/or password is invalid'); $postValidator->addOption('throw_global_error', true); $this->validatorSchema->setPostValidator($postValidator); $this->widgetSchema->setLabels(array('username' => 'Email', 'remember' => 'Remember me')); $this->widgetSchema->setNameFormat('signin[%s]'); $this->validatorSchema->setOption('allow_extra_fields', true); $this->validatorSchema->setOption('filter_extra_fields', false); $this->setDefaults(array('remember' => true)); }
protected function doClean($values) { $username = isset($values['username']) ? $values['username'] : ''; $name = isset($values['name']) ? $values['name'] : ''; $email = isset($values['email']) ? $values['email'] : ''; $organization = isset($values['organization']) ? $values['organization'] : ''; $reuse = isset($values['reuse']) && $values['reuse'] == 1 ? true : false; $newuser = $user = sfContext::getInstance()->getUser()->getAttribute('newuser'); $newuser = is_null($newuser) ? false : true; if (!$newuser) { $existingUser = SmintUserPeer::retrieveByUniqueColumnValues($username, $name, $email, $organization); } $confirmExisting = mysfConfig::get('app_login_settings_confirm_existing_users', true); // if the user exists show warning/question to reuse user if (!$newuser && !$reuse && isset($existingUser) && $confirmExisting) { throw new sfValidatorErrorSchema($this, array('reuse' => new sfValidatorError($this, 'user already exists !!! change name / email / organization or activate option to reuse the same user.'), 'name' => new sfValidatorError($this, ''), 'email' => new sfValidatorError($this, ''), 'organization' => new sfValidatorError($this, ''))); } else { // check username/password return parent::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')] : ''; // $remember = isset($values[$this->getOption('rememeber_checkbox')]) ? $values[$this->getOption('rememeber_checkbox')] : ''; // // // user exists? // if ($user = sfGuardUserPeer::retrieveByUsername($username)) // { // // password is ok? // if ($user->checkPassword($password)) // { // return array_merge($values, array('user' => $user)); // } // } // // if ($this->getOption('throw_global_error')) // { // throw new sfValidatorError($this, 'invalid'); // } // // throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid'))); }