Ejemplo n.º 1
0
 private function validarCampo($valorCampo, array $outrosCampos = array())
 {
     if (isset($outrosCampos['repetir']) && $outrosCampos['repetir'] == 'S') {
         if (empty($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_REQUERIDA);
             return false;
         }
     } elseif (isset($outrosCampos['repetir']) && $outrosCampos['repetir'] == 'N') {
         if (!empty($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_NAO_INFORMAR);
             return false;
         }
     }
     if (!empty($valorCampo)) {
         $stringLenght = new StringLength();
         $stringLenght->setMin('3');
         $stringLenght->setMax('3');
         $stringLenght->setEncoding("UTF-8");
         if (!$stringLenght->isValid($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_VALOR_INVALIDO);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * validate and update user's password
  *
  * @return \Zend\Http\Response|ViewModel
  */
 public function processAction()
 {
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     if ($this->request->isPost()) {
         $form = new RegisterForm();
         $params = $this->params()->fromPost();
         $user = $this->identity();
         if ($this->checkpassword($params['currentPassword'], $user->getPassword())) {
             $filterLength = new StringLength(['min' => 6, 'max' => 50]);
             if ($filterLength->isValid($params['password']) && $params['password'] == $params['confirm_password']) {
                 $user->setPassword($params['password']);
                 $em->persist($user);
                 $em->flush();
                 $this->actionView->setVariable('success', true);
             } else {
                 $this->actionView->setVariables(['error' => true, 'msg' => $filterLength->getMessages()]);
             }
         } else {
             $this->actionView->setVariable('error', true);
         }
         $this->actionView->setTemplate('profile/changepwd/index');
         $this->actionView->setVariable('form', $form);
         return $this->actionView;
     } else {
         return $this->redirect()->toRoute('board/usr');
     }
 }
Ejemplo n.º 3
0
 public function getInputFilter()
 {
     $maxvalidator = new Validator\StringLength();
     $maxvalidator->setMax(50);
     $minvalidator = new Validator\StringLength();
     $minvalidator->setMin(4);
     $email = new Input('email');
     $email->getValidatorChain()->attach(new Validator\EmailAddress());
     $email->getValidatorChain()->attach($maxvalidator);
     $email->getValidatorChain()->attach($minvalidator);
     $password = new Input('password');
     $password->getValidatorChain()->attach($maxvalidator);
     $password->getValidatorChain()->attach(new Validator\StringLength(array('min' => 6)));
     $first_name = new Input('first_name');
     $first_name->getValidatorChain()->attach($maxvalidator);
     $first_name->getValidatorChain()->attach($minvalidator);
     $user_name = new Input('username');
     $user_name->getValidatorChain()->attach($maxvalidator);
     $user_name->getValidatorChain()->attach($minvalidator);
     $inputFilter = new InputFilter();
     $inputFilter->add($email);
     $inputFilter->add($password);
     $inputFilter->add($first_name);
     $inputFilter->add($user_name);
     return $inputFilter;
 }
Ejemplo n.º 4
0
Archivo: Text.php Proyecto: t4web/base
 public function __construct($name = null, $min = 1, $max = 255)
 {
     $validatorStringLength = new Validator\StringLength(array('min' => $min, 'max' => $max));
     $validatorStringLength->setMessages(array(Validator\StringLength::INVALID => "Неверный формат поля", Validator\StringLength::TOO_LONG => "Количество символов в поле не может быть больше " . $max, Validator\StringLength::TOO_SHORT => "Количество символов в поле не может быть меньше " . $min));
     $this->getFilterChain()->attach(new FilterString());
     $this->getValidatorChain()->attach($validatorStringLength);
     parent::__construct($name);
 }
Ejemplo n.º 5
0
 /**
  * @return ValidatorChain
  */
 protected function getTitleValidatorChain()
 {
     $stringLength = new StringLength();
     $stringLength->setMin(5);
     $validatorChain = new ValidatorChain();
     //        $validatorChain->attach(new Alnum(true));
     $validatorChain->attach($stringLength);
     return $validatorChain;
 }
Ejemplo n.º 6
0
 /**
  * Metodo responsavel por criar o validator para min e max length
  *
  * @param integer $intMinLength
  * @param integer $intMaxLength
  * @return $this|bool
  */
 public function setMinAndMaxStringLengthValidator($intMinLength = 0, $intMaxLength = 0)
 {
     if (!$intMinLength && !$intMaxLength) {
         return false;
     }
     $objValidator = new StringLength(['min' => $intMinLength, 'max' => $intMaxLength]);
     $this->getValidatorChain()->attach($objValidator->setMessage($this->strMsgErrorNotEmpty));
     return $this;
 }
Ejemplo n.º 7
0
 public function isValid($value)
 {
     if (null === $value) {
         return true;
     }
     return parent::isValid($value);
 }
Ejemplo n.º 8
0
 /** {@inheritdoc} */
 public function isValid($value)
 {
     if ($value === null) {
         $value = '';
     }
     return parent::isValid($value);
 }
Ejemplo n.º 9
0
 public function __construct(EntityManager $objectManager, $type)
 {
     // Firstname
     $firstname = new Input('prenom');
     $firstname->getFilterChain()->attach(new StringTrim())->attach(new StripTags());
     $firstname->getValidatorChain()->attach(new NotEmpty())->attach(new StringLength(array('max' => 50)));
     $this->add($firstname);
     // Lastname
     $lastname = new Input('nom');
     $lastname->getFilterChain()->attach(new StringTrim())->attach(new StripTags());
     $lastname->getValidatorChain()->attach(new NotEmpty())->attach(new StringLength(array('max' => 50)));
     $this->add($lastname);
     //Unique email validator
     $uniqueUserEmail = new UniqueObject(array('object_manager' => $objectManager, 'object_repository' => $objectManager->getRepository('Application\\Entity\\Utilisateur'), 'fields' => 'email', 'use_context' => true));
     $uniqueUserEmail->setMessage('L\'email renseigné est déjà utilisé par un autre utilisateur.', 'objectNotUnique');
     // Email
     $email = new Input('email');
     $email->getFilterChain()->attach(new StringTrim())->attach(new StripTags());
     $email->getValidatorChain()->attach(new NotEmpty())->attach(new StringLength(array('max' => 255)))->attach(new EmailAddress())->attach($uniqueUserEmail);
     $this->add($email);
     $editCallback = new Callback(function ($value) {
         if ($value == '') {
             return true;
         }
         /** @var StringLength $validator */
         $validator = new StringLength(array('min' => 6, 'max' => 32));
         return $validator->isValid($value);
     });
     $editCallback->setMessage('Le mot de passe doit contenir entre 6 et 32 caractères.');
     // Password
     $password = new Input('password');
     $password->setRequired($type == UtilisateurForm::TYPE_ADD)->setContinueIfEmpty(true);
     $password->getFilterChain()->attach(new StringTrim());
     $password->getValidatorChain()->attach($type == UtilisateurForm::TYPE_ADD ? new StringLength(array('min' => 6, 'max' => 32)) : $editCallback);
     $this->add($password);
     // Password Confirmation
     $passwordConfirmation = new Input('passwordConfirmation');
     $passwordConfirmation->setRequired($type == UtilisateurForm::TYPE_ADD)->setContinueIfEmpty(true);
     $passwordConfirmation->getFilterChain()->attach(new StringTrim());
     $passwordConfirmation->getValidatorChain()->attach($type == UtilisateurForm::TYPE_ADD ? new StringLength(array('min' => 6, 'max' => 32)) : $editCallback)->attach(new Identical('password'));
     $this->add($passwordConfirmation);
     $role = new Input('role');
     $role->setRequired(false);
     $role->getFilterChain()->attach(new Digits());
     $this->add($role);
 }
Ejemplo n.º 10
0
 /**
  * @return bool
  */
 public function validate()
 {
     $this->validateFields($this->getFieldsForValidation(), $this->getData());
     $data = $this->getData();
     $notEmpty = new NotEmpty();
     $stringLength = new StringLength();
     $digits = new Digits();
     if (!$notEmpty->isValid($data['name'])) {
         $this->addError('Name', Validator::ERROR_NOT_EMPTY);
     }
     if (!$stringLength->isValid($data['name'])) {
         $this->addError('Name', Validator::ERROR_NOT_STRING);
     }
     if (!$notEmpty->isValid($data['amount'])) {
         $this->addError('Amount', Validator::ERROR_NOT_EMPTY);
     }
     if (!is_float($data['amount'])) {
         $this->addError('Amount', Validator::ERROR_NOT_AMOUNT);
     }
     if (!$notEmpty->isValid($data['quantity'])) {
         $this->addError('Quantity', Validator::ERROR_NOT_EMPTY);
     }
     if (!$digits->isValid($data['quantity'])) {
         $this->addError('Quantity', Validator::ERROR_NOT_INTEGER);
     }
     if (!$notEmpty->isValid($data['uniqueId'])) {
         $this->addError('uniqueId', Validator::ERROR_NOT_EMPTY);
     }
     if (!$stringLength->isValid($data['uniqueId'])) {
         $this->addError('uniqueId', Validator::ERROR_NOT_STRING);
     }
     // Optional field: Currency
     if (isset($data['currency'])) {
         if (!$stringLength->isValid($data['currency'])) {
             $this->addError('currency', Validator::ERROR_NOT_STRING);
         }
     }
     return $this->confirmValidation();
 }
Ejemplo n.º 11
0
 /**
  * Ensures that getMessageVariables() returns an array of
  * strings and that these strings that can be used as variables
  * in a message.
  */
 public function testGetMessageVariables()
 {
     $vars = $this->validator->getMessageVariables();
     $this->assertInternalType('array', $vars);
     $this->assertEquals(array('min', 'max'), $vars);
     $message = 'variables: %notvar% ';
     foreach ($vars as $var) {
         $message .= "%{$var}% ";
     }
     $this->validator->setMessage($message, StringLength::TOO_SHORT);
     $this->assertFalse($this->validator->isValid('abc'));
     $messages = $this->validator->getMessages();
     $this->assertEquals('variables: %notvar% 4 8 ', current($messages));
 }
Ejemplo n.º 12
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return bool
  * @throws Exception\RuntimeException If validation of $value is impossible
  */
 public function isValid($value)
 {
     if (is_string($value)) {
         //has one lower case
         if (!preg_match('/[a-z]+/', $value) && !preg_match('/[абвгдежзийклмнопрстуфхцчшщъюя]+/', $value)) {
             $this->error(self::MISSING_LOWER_CASE);
         }
         //has one upper case
         if (!preg_match('/[A-Z]+/', $value) && !preg_match('/[АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЮЯ]+/', $value)) {
             $this->error(self::MISSING_UPPER_CASE);
         }
         //has number
         if (!preg_match('/[1-9]+/', $value)) {
             $this->error(self::MISSING_NUMBER);
         }
         if (count($this->getMessages())) {
             return false;
         }
     }
     return parent::isValid($value);
 }
Ejemplo n.º 13
0
 public function getInputFilter()
 {
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $password = new Input('password');
         $password->setRequired(true);
         $password->setAllowEmpty(false);
         $length = new StringLength();
         $length->setMax(20);
         $length->setMin(5);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_LONG);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_SHORT);
         $password->getValidatorChain()->attach($length);
         $this->filter->add($password);
         $passowordRepeat = new Input('passwordRepeat');
         $passowordRepeat->setRequired(true);
         $passowordRepeat->setAllowEmpty(false);
         $passowordRepeat->getValidatorChain()->attach(new Identical('password'));
         $this->filter->add($passowordRepeat);
     }
     return $this->filter;
 }
Ejemplo n.º 14
0
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(array('name' => 'userID', 'required' => true, 'filters' => array(array('name' => 'Int')))));
         //用户名
         $usernameif = $factory->createInput(array('name' => 'username', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
         $validatorChain = new ValidatorChain();
         $v = new StringLength(array('min' => 6, 'max' => 20, 'encoding' => 'UTF-8'));
         $v->setMessages(array(StringLength::TOO_SHORT => '用户名 \'%value%\' 太短了,至少需要6个字符', StringLength::TOO_LONG => '用户名 \'%value%\' 太长了,最多20个字符'));
         $validatorChain->attach($v);
         $v = new NotEmpty();
         $v->setMessage(array(NotEmpty::IS_EMPTY => '用户名不能为空'));
         $validatorChain->attach($v);
         $usernameif->setValidatorChain($validatorChain);
         $inputFilter->add($usernameif);
         //密码
         $psif = $factory->createInput(array('name' => 'upassword', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
         $validatorChain = new ValidatorChain();
         $v = new StringLength(array('min' => 6, 'max' => 20, 'encoding' => 'UTF-8'));
         $v->setMessages(array(StringLength::TOO_SHORT => '密码\'%value%\' 太短了,至少需要6个字符', StringLength::TOO_LONG => '密码 \'%value%\' 太长了,最多20个字符'));
         $validatorChain->attach($v);
         $v = new NotEmpty();
         $v->setMessage(array(NotEmpty::IS_EMPTY => '密码不能为空'));
         $validatorChain->attach($v);
         $psif->setValidatorChain($validatorChain);
         $inputFilter->add($psif);
         /* 原始方法不能改变默认错误信息
                    $inputFilter->add($factory->createInput(array(
                        'name'     => 'upassword',
                        'required' => true,
                        'filters'  => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 6,
                                    'max'      => 20,
                                ),
                            ),
                        ),
                    )));
            */
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
Ejemplo n.º 15
0
 /**
  * change password processing
  * @return ViewModel
  */
 public function updatePwAction()
 {
     $id = $this->params()->fromPost('login_id');
     $pw = $this->params()->fromPost('login_pw');
     $key = $this->params()->fromPost('key_id');
     $new_pw = $this->params()->fromPost('new_pw');
     $token_id = $this->params()->fromPost('token_id');
     $sess_token_id = $this->container()->get('token_id');
     $this->container()->clear('token_id');
     // when can't get require item
     if (!$id || !$pw || !$key || !$new_pw || !$token_id || !$sess_token_id || $token_id != $sess_token_id) {
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     }
     $this->container()->set('login_id', $id);
     $user = new UserEntity();
     $row = $user->db()->getLoginInfo($id, $key);
     $success = false;
     $ngCount = false;
     $message = null;
     if (!$row->user_no) {
         $message = "Unknown account";
         //            $message = "アカウントは不明です。";
     } else {
         if (LOGIN_FAILED_COUNT && LOGIN_FAILED_COUNT <= $row->ng_count) {
             $message = "Account is locked";
             //            $message = "アカウントはロックされています。";
         } else {
             if (!$row->login_pw || md5($row->login_pw . $token_id) != $pw) {
                 $message = "Failed";
                 //            $message = "認証に失敗しました。";
                 $ngCount = true;
             } else {
                 if ($id == $new_pw) {
                     $message = "Don't use same password as ID";
                     //            $message = "ログインIDと同じパスワードは使用できません。";
                 } else {
                     $success = true;
                 }
             }
         }
     }
     // save login error number
     if (!$success && $ngCount) {
         $user->db()->insertLoginFailed($row->user_no);
     }
     if ($success) {
         $ret = $user->db()->checkLoginPw($row->user_no, $new_pw);
         if ($ret) {
             $message = "Don't use same password as past one.";
             //                $message = "過去利用したパスワードは設定出来ません。";
             $success = false;
         }
     }
     $tmp_message = "Confirm password policy\n";
     //        $tmp_message = "パスワードポリシーに違反しています。\n";
     if ($success) {
         $validate = new StringLength();
         $validate->setOptions(array('min' => (int) PW_MIN_LENGTH, 'max' => (int) PW_MAX_LENGTH, 'encoding' => 'UTF-8'));
         $ret = $validate->isValid($new_pw);
         if (!$ret) {
             $message = $tmp_message . current($validate->getMessages());
             $success = false;
         }
     }
     if ($success && strlen(PW_REGEX_PATTERN)) {
         unset($validate);
         $validate = new Regex(array('pattern' => PW_REGEX_PATTERN));
         $ret = $validate->isValid($new_pw);
         if (!$ret) {
             $message = $tmp_message . current($validate->getMessages());
             $success = false;
         }
     }
     // save error message & redirect to input form
     if ($message || !$success) {
         $this->flashMessenger()->addMessage($message);
         return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw'));
     }
     $ret = $user->changePw($row->user_no, $new_pw, 0);
     $message .= 'Change password ' . ($ret ? 'success' : 'failed');
     //                . ($ret ?  '成功しました。' : '失敗しました。');
     $this->flashMessenger()->addMessage($message);
     if ($ret) {
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     } else {
         return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw'));
     }
     $view = new ViewModel();
     $view->setTerminal(true);
     return $view;
 }
Ejemplo n.º 16
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $this->assertFalse($this->validator->isValid(array(1 => 1)));
 }
Ejemplo n.º 17
0
 /**
  * @return void
  */
 public function testDifferentEncodingWithValidator()
 {
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $validator = new Validator\StringLength(2, 2, 'UTF-8');
     $this->assertEquals(true, $validator->isValid('ab'));
     $this->assertEquals('UTF-8', $validator->getEncoding());
     $validator->setEncoding('ISO-8859-1');
     $this->assertEquals('ISO-8859-1', $validator->getEncoding());
 }
Ejemplo n.º 18
0
 /**
  * @param number $min
  * @param number $max
  * @return StringLength
  */
 public static function lengthValidator($min = null, $max = null)
 {
     $validator = new StringLength(compact('min', 'max'));
     if (is_numeric($min) && is_numeric($max)) {
         $validator->setMessage(sprintf("Input tidak boleh kurang dari %s dan lebih dari %s.", $min, $max));
     } else {
         if (is_numeric($min)) {
             $validator->setMessage(sprintf("Input minimal %s karakter.", $min));
         } else {
             if (is_numeric($max)) {
                 $validator->setMessage(sprintf("Input maksimal %s karakter.", $max));
             } else {
                 $validator->setMessage("Input tidak valid.");
             }
         }
     }
     return $validator;
 }
Ejemplo n.º 19
0
 public function getStringLengthValidator()
 {
     if ($this->stringLengthValidator === NULL) {
         $validator = new StringLength();
         $validator->setOptions($this->getStringLengthConfig())->setMessages(array(StringLength::TOO_SHORT => $this->getErrorMessage('STRINGLENGTH::TOO_SHORT'), StringLength::TOO_LONG => $this->getErrorMessage('STRINGLENGTH::TOO_LONG'), StringLength::INVALID => $this->getErrorMessage('STRINGLENGTH::INVALID')));
         $this->setStringLengthValidator($validator);
     }
     return $this->stringLengthValidator;
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function isValid($value)
 {
     $validator = new StringLength($this->options);
     return $validator->isValid($value);
 }