Created
January 15, 2010 13:37
-
-
Save marfillaster/278064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ChangePasswordForm extends BaseForm | |
{ | |
public function configure() | |
{ | |
$this->getWidgetSchema()->setLabel('old', 'Old Password'); | |
$this->getWidgetSchema()->setLabel('new', 'New Password'); | |
$this->getWidgetSchema()->setLabel('repeat', 'Repeat New Password'); | |
$this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'postValidate')))); | |
$this->mergePostValidator(new sfValidatorSchemaCompare('new', sfValidatorSchemaCompare::EQUAL, 'repeat', array(), array('invalid' => 'The two passwords must be the same.'))); | |
} | |
public function postValidate($validator, $values) | |
{ | |
if($values['old'] && !$this->getOption('sf_user')->checkPassword($values['old'])) | |
{ | |
throw new sfValidatorError($validator, 'Old password is incorrect'); | |
} | |
return $values; | |
} | |
public function setup() | |
{ | |
$this->setWidgets(array( | |
'old' => new sfWidgetFormInputPassword(), | |
'new' => new sfWidgetFormInputPassword(), | |
'repeat' => new sfWidgetFormInputPassword() | |
)); | |
$this->setValidators(array( | |
'old' => new sfValidatorString(), | |
'new' => new sfValidatorString(), | |
'repeat' => new sfValidatorString(array('required' => false)), | |
)); | |
$this->widgetSchema->setNameFormat('password[%s]'); | |
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); | |
parent::setup(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment