コード例 #1
0
ファイル: DAOImpl.php プロジェクト: Aasit/DISCOUNT--SRV-I
 private function _validate($param, $type)
 {
     $libConfig = $GLOBALS['app']->getConfiguration()->getRawConfiguration('library');
     $minNameVal = $libConfig["product"]["minNameLength"];
     $maxNameVal = $libConfig["product"]["maxNameLength"];
     $minCodeVal = $libConfig["product"]["minCodeLength"];
     $maxCodeVal = $libConfig["product"]["maxCodeLength"];
     $validateName = v::alnum('-_')->length($minNameVal, $maxNameVal);
     $validateCode = v::alnum('-_')->noWhitespace()->length($minCodeVal, $maxCodeVal);
     $validateToken = v::alnum('-_');
     if (strcmp($type, "name") === 0) {
         $isValid = $validateName->validate($param);
         if (!$isValid) {
             throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_NAME, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
         }
     } else {
         if (strcmp($type, "code") === 0) {
             $isValid = $validateCode->validate($param);
             if (!$isValid) {
                 throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_CODE, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
             }
         } else {
             if (strcmp($type, "token") === 0) {
                 $isValid = $validateToken->validate($param);
                 if (!$isValid) {
                     throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_TOKEN, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
                 }
             } else {
                 throw new \InvalidArgumentException('Invalid Validation Type', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
             }
         }
     }
 }
コード例 #2
0
ファイル: Product.php プロジェクト: dafiti/datajet-client
 private function validateConfig(array $config)
 {
     if (empty($config)) {
         throw new \InvalidArgumentException('Empty config is not allowed');
     }
     $validator = v::arrayVal()->notEmpty()->key('search', v::arrayVal()->notEmpty()->key('uri', v::url()->notEmpty())->key('key', v::alnum()->notEmpty()))->key('data', v::arrayVal()->notEmpty()->key('uri', v::url()->notEmpty())->key('key', v::alnum()->notEmpty()));
     $validator->assert($config);
 }
コード例 #3
0
 public function criptografaSenha($senha)
 {
     $senhaCriptografada = null;
     $senhaValidador = Validator::alnum()->notEmpty()->noWhitespace()->length(4, 20);
     try {
         $senhaValidador->check($senha);
         $senhaCriptografada = md5($senha);
     } catch (ValidationException $exception) {
         print_r($exception->getMainMessage());
     }
     return $senhaCriptografada;
 }
コード例 #4
0
 public function output($request, $response, $args)
 {
     $query = $request->getQueryParams();
     $validator = v::key('a', v::stringType()->length(1, 32))->key('b', v::alnum());
     list($ok, $message) = $this->validate($validator, $query);
     if (!$ok) {
         return $this->view->error('INPUT_ERROR', $message);
     }
     $ret = array();
     for ($i = 0; $i < 4; $i++) {
         $ret[] = array('data' => $i);
     }
     return $this->view->render($ret);
 }
コード例 #5
0
 public function validateAddress($address)
 {
     //@TODO: properly check all types.. strings need to be double checked for alnum, cause of typecasting.
     $rules = v::key('firstname', v::notEmpty()->setName('First name'))->key('lastname', v::notEmpty()->setName('Last name'))->key('address', v::alnum(".,-'")->notEmpty()->setName('Address'))->key('secondary_address', v::when(v::notEmpty(), v::alnum(".,-'"), v::alwaysValid())->setName('Address 2'))->key('city', v::alnum()->notEmpty()->setName('City'))->key('state', v::alnum()->notEmpty()->setName('State'))->key('zip', v::when(v::notEmpty(), v::postalCode('US'), v::alwaysValid())->notEmpty()->setName('Zipcode'));
     if ($rules->validate($address)) {
         return true;
     }
     try {
         $rules->check($address);
     } catch (ValidationExceptionInterface $exception) {
         //            $this->error = $exception->getMainMessage();
     }
     return false;
 }
コード例 #6
0
 public function test_findMessages_should_apply_templates_to_flattened_messages()
 {
     $stringMax256 = v::string()->length(5, 256);
     $alnumDot = v::alnum('.');
     $stringMin8 = v::string()->length(8, null);
     $v = v::allOf(v::attribute('first_name', $stringMax256)->setName('First Name'), v::attribute('last_name', $stringMax256)->setName('Last Name'), v::attribute('desired_login', $alnumDot)->setName('Desired Login'), v::attribute('password', $stringMin8)->setName('Password'), v::attribute('password_confirmation', $stringMin8)->setName('Password Confirmation'), v::attribute('stay_signedin', v::notEmpty())->setName('Stay signed in'), v::attribute('enable_webhistory', v::notEmpty())->setName('Enabled Web History'), v::attribute('security_question', $stringMax256)->setName('Security Question'))->setName('Validation Form');
     try {
         $v->assert((object) array('first_name' => 'fiif', 'last_name' => null, 'desired_login' => null, 'password' => null, 'password_confirmation' => null, 'stay_signedin' => null, 'enable_webhistory' => null, 'security_question' => null));
     } catch (ValidationException $e) {
         $messages = $e->findMessages(array('allOf' => 'Invalid {{name}}', 'first_name.length' => 'Invalid length for {{name}} {{input}}'));
         $this->assertEquals($messages['allOf'], 'Invalid Validation Form');
         $this->assertEquals($messages['first_name_length'], 'Invalid length for "fiif" fiif');
     }
 }
コード例 #7
0
ファイル: AccountController.php プロジェクト: Swader/nofw
 /**
  * @auth-groups users
  */
 public function saveAction()
 {
     if (!empty($_POST['password_new'])) {
         try {
             v::length(6)->check($_POST['password_new']);
         } catch (ValidationException $e) {
             $this->flasher->error('Please make sure new password is longer than 6 characters!');
         }
         if ($_POST['password_new'] !== $_POST['password_new_confirm']) {
             $this->flasher->error('New password fields were not identical!');
         }
         if (!Gatekeeper::authenticate(['username' => $this->user->username, 'password' => $_POST['password_old']])) {
             $this->flasher->error('Invalid password. Changes ignored.');
         } else {
             $this->user->password = $_POST['password_new'];
             $this->user->save();
             $this->flasher->success('Password updated!');
         }
     }
     if ($_POST['firstname'] != '-') {
         try {
             v::alnum(' ')->check($_POST['firstname']);
             $this->user->firstName = $_POST['firstname'];
             $this->user->save();
             $this->flasher->success('First name changed.');
         } catch (ValidationException $e) {
             $this->flasher->error('Name contains invalid characters. ' . $e->getMainMessage());
         }
     }
     if ($_POST['lastname'] != '-') {
         try {
             v::alnum(' ')->check($_POST['lastname']);
             $this->user->lastName = $_POST['lastname'];
             $this->user->save();
             $this->flasher->success('Last name changed.');
         } catch (ValidationException $e) {
             $this->flasher->error('Last name contains invalid characters. ' . $e->getMainMessage());
         }
     }
     $this->redirect('/account');
 }
コード例 #8
0
ファイル: UsersController.php プロジェクト: Swader/nofw
 public function upsertGroupProcessAction()
 {
     $id = $_POST['id'] ?? null;
     if ($id && !ctype_digit($id)) {
         $this->flasher->error('E01 Invalid group ID: ' . $id);
         $this->redirect('/users/groups');
     }
     $group = null;
     if ($id) {
         $group = Gatekeeper::findGroupById($id);
         if (!$group) {
             $this->flasher->error('E02 Invalid group ID: ' . $id);
         }
     }
     try {
         v::alnum('-._')->setName('Group name')->check($_POST['name']);
     } catch (ValidationException $e) {
         $this->flasher->error($e->getMainMessage());
         echo $this->twig->render('users/groups/upsert.twig', ['flashes' => $this->flasher->display(), 'group' => $group ?: $_POST]);
         return false;
     }
     if ($group) {
         $group->name = $_POST['name'];
         $group->description = $_POST['description'];
         $group->save();
     } else {
         Gatekeeper::createGroup($_POST);
         if (Gatekeeper::getLastError()) {
             $this->flasher->error($this->site['debug'] ? Gatekeeper::getLastError() : "Could not create group!");
             echo $this->twig->render('users/groups/upsert.twig', ['flashes' => $this->flasher->display(), 'user' => $group ?: $_POST]);
             return false;
         }
         $this->flasher->success('Successfully created group.');
         $this->redirect('/users/groups');
     }
 }
コード例 #9
0
 private static function UsuarioValido($request)
 {
     $usernameValidator = validator::alnum()->noWhitespace()->length(4, 15);
     $escuelaValidator = validator::alnum("()")->length(3, 50);
     try {
         $usernameValidator->check($request["nick"]);
         if (array_key_exists("escuela", $request)) {
             $escuelaValidator->check($request["escuela"]);
         }
     } catch (InvalidArgumentException $e) {
         return false;
     }
     return true;
 }
コード例 #10
0
ファイル: ControllerCommand.php プロジェクト: bluzphp/bluzman
 protected function getOptions()
 {
     return [['module', null, InputOption::VALUE_OPTIONAL, ' name of module.', null, v::alnum('-')->noWhitespace()], ['name', null, InputOption::VALUE_OPTIONAL, ' name of new controller.', null, v::alnum('-')->noWhitespace()]];
 }
コード例 #11
0
ファイル: ModelCommand.php プロジェクト: bluzphp/bluzman
 protected function getOptions()
 {
     return [['name', null, InputOption::VALUE_OPTIONAL, ' name of model.', null, v::alnum('-')->noWhitespace()], ['table', null, InputOption::VALUE_OPTIONAL, ' name of table.', null, v::alnum('-')->noWhitespace()]];
 }
コード例 #12
0
ファイル: AllCommand.php プロジェクト: bluzphp/bluzman
 /**
  * Get the console command options.
  *
  * @return array
  */
 protected function getOptions()
 {
     return [['name', null, InputOption::VALUE_OPTIONAL, 'Name of new project', null, v::alnum('_-')->noWhitespace()], ['path', null, InputOption::VALUE_OPTIONAL, 'Project root path', null, v::directory()->writable()]];
 }
コード例 #13
0
ファイル: LoginAction.php プロジェクト: aodkrisda/notes-api
 private function validate($input)
 {
     $validator = v::key('username', v::alnum()->notEmpty()->noWhitespace())->key('password', v::stringType()->notEmpty()->length(3, 20));
     $validator->assert($input);
 }
コード例 #14
0
ファイル: Validation.php プロジェクト: ignaszak/cms
 /**
  *
  * @param string $password
  * @return boolean
  */
 public function password($password) : bool
 {
     return V::alnum()->noWhitespace()->length(8, null)->validate($password);
 }
コード例 #15
0
ファイル: Cartao.php プロジェクト: mrprompt/cielo
 /**
  * Seta o nome do portador do cartão
  *
  * @access public
  * @param  string $nomePortador
  * @return Cartao
  */
 public function setNomePortador($nomePortador)
 {
     if (!v::alnum()->notEmpty()->validate($nomePortador)) {
         throw new InvalidArgumentException('Caracteres inválidos no nome do portador.');
     }
     $this->nomePortador = substr($nomePortador, 0, 50);
     return $this;
 }
コード例 #16
0
ファイル: ModuleCommand.php プロジェクト: bluzphp/bluzman
 protected function getOptions()
 {
     return [['name', null, InputOption::VALUE_OPTIONAL, 'The name of module.', null, v::alnum('_-')->noWhitespace()]];
 }
コード例 #17
0
ファイル: Group.php プロジェクト: enpowi/enpowi
 public static function isValidGroupName($groupName)
 {
     return v::alnum()->noWhitespace()->length(3, 200)->validate($groupName);
 }
コード例 #18
0
 public function testComplexXmlValidationWithErrors()
 {
     $xml = '<person>
       <type>emails</type>
       <objectid>1</objectid>
       <email>
         <id>1</id>
         <enable_mapping>1</enable_mapping>
         <name>rq3r</name>
         <created_at>2016-08-23 13:36:29</created_at>
         <updated_at>2016-08-23 14:36:47</updated_at>
       </email>
     </person>';
     $this->setUpXmlPost($xml);
     $typeValidator = v::alnum()->noWhitespace()->length(3, 5);
     $emailNameValidator = v::alnum()->noWhitespace()->length(1, 2);
     $validators = array('type' => $typeValidator, 'email' => array('name' => $emailNameValidator));
     $mw = new Validation($validators);
     $next = function ($req, $res) {
         return $res;
     };
     $response = $mw($this->request, $this->response, $next);
     $errors = array('type' => array('"emails" must have a length between 3 and 5'), 'email.name' => array('"rq3r" must have a length between 1 and 2'));
     $this->assertEquals($errors, $mw->getErrors());
     $this->assertEquals($validators, $mw->getValidators());
 }
コード例 #19
0
ファイル: ValidatorTest.php プロジェクト: 00F100/Validation
 public function testDoNotRelyOnNestedValidationExceptionInterfaceForCheck()
 {
     $usernameValidator = Validator::alnum('_')->length(1, 15)->noWhitespace();
     try {
         $usernameValidator->check('really messed up screen#name');
     } catch (NestedValidationExceptionInterface $e) {
         $this->fail('Check used NestedValidationException');
     } catch (ValidationExceptionInterface $e) {
         $this->assertTrue(true);
     }
 }
コード例 #20
0
/**
 * Validates input type
 *
 * @param string           $hook       "validate:type"
 * @param string           $type       "prototyper"
 * @param ValidationStatus $validation Current validation status
 * @param array            $params     Hook params
 * @return ValidationStatus
 */
function prototyper_validate_type($hook, $type, $validation, $params)
{
    if (!$validation instanceof ValidationStatus) {
        $validation = new ValidationStatus();
    }
    $field = elgg_extract('field', $params);
    if (!$field instanceof Field) {
        return $validation;
    }
    $rule = elgg_extract('rule', $params);
    if ($rule != "type") {
        return $validation;
    }
    $value = elgg_extract('value', $params);
    $expectation = elgg_extract('expectation', $params);
    switch ($expectation) {
        case 'text':
        case 'string':
            if (!v::string()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:string', array($field->getLabel())));
            }
            break;
        case 'alnum':
        case 'alphanum':
            if (!v::alnum()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:alnum', array($field->getLabel())));
            }
            break;
        case 'alpha':
            if (!v::alpha()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:alpha', array($field->getLabel())));
            }
            break;
        case 'number':
        case 'numeric':
            if (!v::numeric()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:numeric', array($field->getLabel())));
            }
            break;
        case 'integer':
        case 'int':
            if (!v::int()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:int', array($field->getLabel())));
            }
            break;
        case 'date':
            if (!v::date()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:date', array($field->getLabel())));
            }
            break;
        case 'url':
            if (!v::filterVar(FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:url', array($field->getLabel())));
            }
            break;
        case 'email':
            if (!v::filterVar(FILTER_VALIDATE_EMAIL)->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:email', array($field->getLabel())));
            }
            break;
        case 'guid':
        case 'entity':
            if (!elgg_entity_exists($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:guid', array($field->getLabel())));
            }
            break;
        case 'image':
            $type = elgg_extract('type', $value);
            if (!$type || substr_count($type, 'image/') == 0) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:image', array($field->getLabel())));
            }
            break;
    }
    return $validation;
}
コード例 #21
0
ファイル: Transacao.php プロジェクト: mrprompt/cielo
 /**
  * Configura o TID
  *
  * @access public
  * @param  string $tid
  * @return Cielo
  */
 public function setTid($tid)
 {
     if (!v::alnum()->notEmpty()->validate($tid)) {
         throw new InvalidArgumentException('Caracteres inválidos no TID.');
     }
     $this->tid = $tid;
     return $this;
 }
 private function validateSoftDescriptor($parameters)
 {
     $fieldName = "soft_descriptor";
     if (array_key_exists($fieldName, $parameters)) {
         if (!v::length(1, 13, true)->validate($parameters[$fieldName]) || !v::alnum()->noWhitespace()->validate($parameters[$fieldName])) {
             $this->validationResponse->status = s::VALIDATION_ERROR;
             $this->validationResponse->errors[$fieldName] = "is invalid";
             return false;
         }
     }
     return true;
 }
コード例 #23
0
 $emp_fname = $form_data['emp_fname'];
 $emp_lname = $form_data['emp_lname'];
 // ========================================================================================
 // FILTER DATA: VALIDATE
 // ========================================================================================
 // Alphanumeric with some typical symbols
 if (v::not(v::alnum("-.,()'"))->validate($form_data['requester_fname'])) {
     $err_msg .= "Your first name must be alphanumeric.\\n";
 }
 if (v::not(v::alnum("-.,()'"))->validate($form_data['requester_lname'])) {
     $err_msg .= "Your last name must be alphanumeric.\\n";
 }
 if (v::not(v::alnum("-.,()'"))->validate($form_data['emp_fname'])) {
     $err_msg .= "The first name of the employee must be alphanumeric.\\n";
 }
 if (v::not(v::alnum("-.,()'"))->validate($form_data['emp_lname'])) {
     $err_msg .= "The last name of the employee must be alphanumeric.\\n";
 }
 //if(v::not(v::alnum("-.,()'"))->validate($form_data['account_number'])) { $err_msg .= "The account number must be alphanumeric.\\n"; }
 // Phone
 if (v::not(v::phone())->validate($form_data['requester_phone'])) {
     $err_msg .= "Your phone number is not valid: " . $form_data['requester_phone'] . "\\n";
 }
 if (v::not(v::phone())->validate($form_data['dept_phone'])) {
     $err_msg .= "The department phone number is not valid: " . $form_data['dept_phone'] . "\\n";
 }
 // Date or Time - should not be in future
 if (v::not(v::date('Y-m-d')->max('today'))->validate($mysql_start_date)) {
     $err_msg .= "The start date is invalid: " . $start_date . "\\n";
 }
 if (v::not(v::date('Y-m-d')->max('today'))->validate($mysql_end_date)) {
コード例 #24
0
ファイル: WorkerCfg.php プロジェクト: bsmrs/bughunter
 /**
  * @param String $name
  * @return WorkerCfg
  */
 public function setName($name)
 {
     Validator::alnum('_')->noWhitespace()->notEmpty()->length(1, 255)->check($name);
     $this->name = $name;
     return $this;
 }
コード例 #25
0
 /**
  * Verifica se o valor possui apenas caracteres de a-Z, 0-9 e espaços
  * @param string $value
  * @param array $params Lista de flags
  * @return boolean
  */
 public function validAlnum($value, $params = array())
 {
     if (!v::alnum()->validate($value)) {
         if (getValueFromArray($params, Flag::NOWHITESPACE, false)) {
             Factory::log()->warn('Valor deve possuir apenas letras e números');
         } else {
             Factory::log()->warn('Valor deve possuir apenas letras, números e espaços');
         }
         return false;
     }
     return true;
 }