Пример #1
0
 public function buildFilter()
 {
     //category char 16 not null,
     $category = new Input('category');
     $category->setAllowEmpty(TRUE);
     $category->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags')->attachByName('StringToLower');
     $category->getValidatorChain()->attachByName('inArray', array('haystack' => $this->categories));
     //title varchar 128 not null
     $title = new Input('title');
     $title->setAllowEmpty(TRUE);
     $title->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $titleRegex = new Regex(array('pattern' => '/^[a-zA-Z0-9 ]*$/'));
     $titleRegex->setMessage('Title should contain only numbers, letters or spaces.');
     $title->getValidatorChain()->attach($titleRegex)->attachByName('StringLength', array('min' => 1, 'max' => 128));
     //date_created timestamp not null default current_timestamp
     $dateCreated = new Input('dateCreated');
     $dateCreated->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $dateCreated->getValidatorChain()->attachByName('StringLength', array('min' => 10, 'max' => 10));
     // 	    date_expires timestamp not null default null
     // 	    descripton varchar 4096 default null
     // 	    photo_filename varchar 1024 default null
     // 	    contact_name varchar 255 default null
     // 	    contact_email varchar 255 default null
     // 	    contact_phone varchar 32 default null
     // 	    city varchar 128 default null
     // 	    country char 2 not null
     // 	    price decimal 12,2 not null
     // 	    delete_code char 16 character set utf8 collate utf8_bin default null
     $this->add($category)->add($title)->add($dateCreated);
 }
Пример #2
0
 /**
  * Trims and validates password against regex
  * 
  * @param string $password
  * @return string
  * @throws Exception
  */
 public static function validatePassword($password)
 {
     $validator = new Regex(['pattern' => '/((?=.*\\d)(?=.*[a-zA-Z]).{8,20})/U']);
     if (!$validator->isValid((new StringTrim())->filter($password))) {
         throw new Exception(Json::encode($validator->getMessages()));
     }
     return $password;
 }
Пример #3
0
 /**
  * @return RegexValidator
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/' . self::PHONE_FORMAT . '/');
         $validator->setMessage('Must be a 10-digit phone number with area code', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #4
0
 /**
  * Get a validator if none has been set.
  * https://github.com/posabsolute/jQuery-Validation-Engine/issues/265
  * @return ValidatorInterface
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/^([\\+][0-9]{1,3}[ \\.\\-])?([\\(]{1}[0-9]{1,6}[\\)])?([0-9 \\.\\-\\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/');
         $validator->setMessage('Please enter a phone Number. You can use the intenational format. Only digits and \'+\'.', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #5
0
 /**
  * @return RegexValidator
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/' . self::CURRENCY_FORMAT . '/');
         $validator->setMessage('Must be in US currency including dollar sign', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #6
0
 /**
  * Get a validator if none has been set.
  * @return ValidatorInterface
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/^([0-9\\(\\)\\/\\+ \\-]*)$/');
         $validator->setMessage('Please use digits only', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #7
0
 public function buildFilter()
 {
     /******************************************************************
      * Isto é um exemplo de como realizar a configurações do filtro,
      * O importante é registrar o campos do formulário pedidos no exercícios
      **********************************************************************/
     // filter & validate by fields
     $category = new Input('category');
     $category->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags')->attachByName('StringToLower');
     $category->getValidatorChain()->attachByName('InArray', array('haystack' => $this->getCategories()));
     $title = new Input('title');
     $title->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $titleRegex = new Regex(array('pattern' => '/^[a-zA-Z0-9 ]*$/'));
     $titleRegex->setMessage('Title should only contain numbers, letters or spaces!');
     $title->getValidatorChain()->attach($titleRegex)->attachByName('StringLength', array('min' => 1, 'max' => 128));
     $photo = new Input('photo_filename');
     $photo->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $photo->getValidatorChain()->attachByName('Regex', array('pattern' => '!^(http://)?[a-z0-9./_-]+(jp(e)?g|png)$!i'));
     $photo->setErrorMessage('Photo must be a URL or a valid filename ending with jpg or png');
     $price = new Input('price');
     $price->setAllowEmpty(TRUE);
     $price->getValidatorChain()->addByName('GreaterThan', array('min' => 0.0));
     $price->getFilterChain()->attach(new Float());
     // custom filter
     $expires = new Input('expires');
     $expires->setAllowEmpty(TRUE);
     $expires->getValidatorChain()->attachByName('InArray', array('haystack' => array_keys($this->getExpireDays())));
     $expires->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $city = new Input('cityCode');
     $city->setAllowEmpty(TRUE);
     $city->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $name = new Input('contact_name');
     $name->setAllowEmpty(TRUE);
     $name->getValidatorChain()->attachByName('Regex', array('pattern' => '/^[a-z0-9., -]{1,255}$/i'));
     $name->setErrorMessage('Name should only contain letters, numbers, and some punctuation.');
     $name->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $phone = new Input('contact_phone');
     $phone->setAllowEmpty(TRUE);
     $phone->getValidatorChain()->attachByName('Regex', array('pattern' => '/^\\+?\\d{1,4}(-\\d{3,4})+$/'));
     $phone->setErrorMessage('Phone number must be in this format: +nnnn-nnn-nnn-nnnn');
     $phone->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $email = new Input('contact_email');
     $email->setAllowEmpty(TRUE);
     $email->getValidatorChain()->attachByName('EmailAddress');
     $email->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $description = new Input('description');
     $description->setAllowEmpty(TRUE);
     $description->getValidatorChain()->attachByName('StringLength', array('min' => 1, 'max' => 4096));
     $description->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $delCode = new Input('delete_code');
     $delCode->setRequired(TRUE);
     $delCode->getValidatorChain()->addByName('Digits');
     $this->add($category)->add($title)->add($photo)->add($price)->add($expires)->add($city)->add($name)->add($phone)->add($email)->add($description)->add($delCode);
 }
Пример #8
0
 /**
  * Validate nickname of customer
  * @return array|bool|\string[]
  */
 public function validate()
 {
     $errors = [];
     $validator = new Regex(array('pattern' => '/^[a-zA-Z0-9]*[^_]*$/'));
     if ($validator->isValid($this->getNickname())) {
         $errors[] = __('Your nickname should not contain dashes. Please try again');
     }
     if (!empty($errors)) {
         return $errors;
     }
     return parent::validate();
 }
Пример #9
0
 /**
  * testing create without a data
  */
 public function testCreateNoData()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $this->request->setMethod('post');
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertNotEquals(1, $result->success);
     //test that message contains isEmpty
     $validator = new Regex(['pattern' => '/isEmpty/U']);
     //U - non greedy
     $this->assertFalse($validator->isValid($result->message));
 }
 public function testCreateWithoutGradingType()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $name = 'Gradingtype name' . uniqid();
     $this->request->setMethod('post');
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals(null, $result->success);
     //test that message contains gradingType":{"isEmpty
     $validator = new Regex(['pattern' => '/name.{4}isEmpty/U']);
     $this->assertTrue($validator->isValid($result->message));
 }
 /**
  * Should be NOT successful
  */
 public function testCreateNoStudentGroup()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $status = rand(0, 1);
     $this->request->setMethod('post');
     $this->request->getPost()->set('student', $this->CreateStudent()->getId());
     $this->request->getPost()->set('status', $status);
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, FALSE);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals(false, $result->success);
     //test that message contains studentGroup":{"isEmpty
     $validator = new Regex(['pattern' => '/studentGroup.{4}isEmpty/U']);
     $this->assertTrue($validator->isValid($result->message));
 }
Пример #12
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;
 }
Пример #13
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $validator = new Validator\Regex('/./');
     $this->assertFalse($validator->isValid(array(1 => 1)));
 }
Пример #14
0
 /**
  * @ZF-11863
  * @dataProvider specialCharValidationProvider
  */
 public function testSpecialCharValidation($expected, $input)
 {
     // Locale changed due a bug with PHP versions lower than 5.3.4 (https://bugs.php.net/bug.php?id=52971)
     //setlocale(LC_ALL, 'Spanish_Spain', 'es_ES', 'es_ES.utf-8');
     if (version_compare(PHP_VERSION, '5.3.4', '<')) {
         $this->markTestIncomplete("Test skipped because the PHP version is lower than 5.3.4 or the environment don't support quoted characters");
     }
     $validator = new Regex('/^[[:alpha:]\']+$/iu');
     $this->assertEquals($expected, $validator->isValid($input), 'Reason: ' . implode('', $validator->getMessages()));
 }
Пример #15
0
 /**
  * @ZF-11863
  * @dataProvider specialCharValidationProvider
  */
 public function testSpecialCharValidation($expected, $input)
 {
     $validator = new Regex('/^[[:alpha:]\']+$/iu');
     $this->assertEquals($expected, $validator->isValid($input), 'Reason: ' . implode('', $validator->getMessages()));
 }
Пример #16
0
 public function __construct()
 {
     parent::__construct(self::$defaultPattern);
 }
 /**
  * Should be NOT successful
  */
 public function testCreateNoTeacher()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $this->request->setMethod('post');
     $subject = $this->CreateSubject();
     $this->request->getPost()->set("subject", $subject->getId());
     $studentGroup = $this->CreateStudentGroup();
     $this->request->getPost()->set("studentGroup", $studentGroup->getId());
     $module = $this->CreateModule();
     $this->request->getPost()->set("module", $module->getId());
     $vocation = $this->CreateVocation();
     $this->request->getPost()->set("vocation", $vocation->getId());
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals(false, $result->success);
     //test that message contains No result was found
     $validator = new Regex(['pattern' => '/No result was found/U']);
     $this->assertTrue($validator->isValid($result->message));
 }
Пример #18
0
 /**
  * Should be NOT successful
  */
 public function testCreateNoModuleType()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $this->request->setMethod('post');
     $this->request->getPost()->set("gradingType", [['id' => $this->CreateGradingType()->getId()], ['id' => $this->CreateGradingType()->getId()]]);
     $this->request->getPost()->set("vocation", $this->CreateVocation()->getId());
     $this->request->getPost()->set("name", "Test Tere Maailm");
     $this->request->getPost()->set("duration", "30");
     $this->request->getPost()->set("moduleCode", uniqid());
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals(null, $result->success);
     //test that message contains moduleType":{"isEmpty
     $validator = new Regex(['pattern' => '/moduleType.{4}isEmpty/U']);
     $this->assertTrue($validator->isValid($result->message));
 }
Пример #19
0
 /**
  * {@inheritdoc}
  */
 public function isValid($value)
 {
     $validator = new Regex($this->options);
     return $validator->isValid($value);
 }
Пример #20
0
 /**
  * Should be NOT successful
  */
 public function testCreateNoContactLesson()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $this->request->setMethod('post');
     $description = 'Absence description' . uniqid();
     $this->request->getPost()->set('description', $description);
     $this->request->getPost()->set('student', $this->CreateStudent()->getId());
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals(false, $result->success);
     $validator = new Regex(['pattern' => '/contactLesson.{4}isEmpty/U']);
     $this->assertTrue($validator->isValid($result->message));
 }
Пример #21
0
 /**
  * @ZF-11863
  */
 public function testSpecialCharValidation()
 {
     /**
      * The elements of each array are, in order:
      *      - pattern
      *      - expected validation result
      *      - array of test input values
      */
     $valuesExpected = array(array('/^[[:alpha:]\']+$/iu', true, array('test', 'òèùtestòò', 'testà', 'teààst', 'ààòòìùéé', 'èùòìiieeà')), array('/^[[:alpha:]\']+$/iu', false, array('test99')));
     foreach ($valuesExpected as $element) {
         $validator = new Validator\Regex($element[0]);
         foreach ($element[2] as $input) {
             $this->assertEquals($element[1], $validator->isValid($input));
         }
     }
 }
 /**
  * Should be NOT successful
  */
 public function testCreateNoTeacher()
 {
     //create user
     $administrator = $this->CreateAdministrator();
     $lisUser = $this->CreateAdministratorUser($administrator);
     //now we have created adminuser set to current controller
     $this->controller->setLisUser($lisUser);
     $this->controller->setLisPerson($administrator);
     $this->request->setMethod('post');
     $lessonDate = new \DateTime();
     $description = ' Description for contactlesson' . uniqid();
     $sequenceNr = 4;
     $subjectRound = $this->CreateSubjectRound()->getId();
     $this->request->getPost()->set("lessonDate", $lessonDate);
     $this->request->getPost()->set("sequenceNr", $sequenceNr);
     $this->request->getPost()->set('subjectRound', $subjectRound);
     $this->request->getPost()->set("description", $description);
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->PrintOut($result, false);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertNotEquals(1, $result->success);
     //test that message is: No result was found for query although at least one row was expected.
     $validator = new Regex(['pattern' => '/No result was found/U']);
     $this->assertFalse($validator->isValid($result->message));
 }