Example #1
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;
 }
 /**
  * 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();
 }
 /**
  * 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));
 }
Example #5
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 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));
 }
Example #7
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;
 }
Example #8
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $validator = new Validator\Regex('/./');
     $this->assertFalse($validator->isValid(array(1 => 1)));
 }
Example #9
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()));
 }
Example #10
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()));
 }
 /**
  * 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));
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function isValid($value)
 {
     $validator = new Regex($this->options);
     return $validator->isValid($value);
 }
 /**
  * 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));
 }
 /**
  * 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));
 }
 /**
  * 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));
 }