コード例 #1
0
 /**
  * Adds validation rule for user password confirmation
  *
  * @param \Magento\Framework\Validator\Object $validator
  * @param string $passwordConfirmation
  * @return \Magento\Framework\Validator\Object
  */
 public function addPasswordConfirmationRule(\Magento\Framework\Validator\Object $validator, $passwordConfirmation)
 {
     $passwordConfirmation = new \Zend_Validate_Identical($passwordConfirmation);
     $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME);
     $validator->addRule($passwordConfirmation, 'password');
     return $validator;
 }
コード例 #2
0
 public function testAddRule()
 {
     $actualResult = $this->_model->addRule(new \Zend_Validate_Identical('field_one_value'), 'field_one');
     $this->assertSame($this->_model, $actualResult, 'Methods chaining is broken.');
 }
コード例 #3
0
ファイル: User.php プロジェクト: pavelnovitsky/magento2
 /**
  * Add validation rules for the password management fields
  *
  * @param \Magento\Framework\Validator\Object $validator
  * @return void
  */
 protected function _addPasswordValidation(\Magento\Framework\Validator\Object $validator)
 {
     $passwordNotEmpty = new \Zend_Validate_NotEmpty();
     $passwordNotEmpty->setMessage(__('Password is required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $minPassLength = self::MIN_PASSWORD_LENGTH;
     $passwordLength = new \Zend_Validate_StringLength(array('min' => $minPassLength, 'encoding' => 'UTF-8'));
     $passwordLength->setMessage(__('Your password must be at least %1 characters.', $minPassLength), \Zend_Validate_StringLength::TOO_SHORT);
     $passwordChars = new \Zend_Validate_Regex('/[a-z].*\\d|\\d.*[a-z]/iu');
     $passwordChars->setMessage(__('Your password must include both numeric and alphabetic characters.'), \Zend_Validate_Regex::NOT_MATCH);
     $validator->addRule($passwordNotEmpty, 'password')->addRule($passwordLength, 'password')->addRule($passwordChars, 'password');
     if ($this->hasPasswordConfirmation()) {
         $passwordConfirmation = new \Zend_Validate_Identical($this->getPasswordConfirmation());
         $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME);
         $validator->addRule($passwordConfirmation, 'password');
     }
 }