Since: 2.2.0
Author: Henry Ruhs
Inheritance: implements Redaxscript\Validator\ValidatorInterface
示例#1
0
 /**
  * testCaptcha
  *
  * @since 2.2.0
  *
  * @param string $raw
  * @param string $hash
  * @param integer $expect
  *
  * @dataProvider providerValidatorCaptcha
  */
 public function testCaptcha($raw = null, $hash = null, $expect = null)
 {
     /* setup */
     $validator = new Validator\Captcha();
     /* result */
     $result = $validator->validate($raw, $hash);
     /* compare */
     $this->assertEquals($expect, $result);
 }
 /**
  * testCaptcha
  *
  * @since 2.6.0
  *
  * @param string $task
  * @param array $hashArray
  * @param integer $expect
  *
  * @dataProvider providerCaptcha
  */
 public function testCaptcha($task = null, $hashArray = array(), $expect = null)
 {
     /* setup */
     $validator = new Validator\Captcha();
     /* actual */
     $actual = $validator->validate($task, function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
     /* compare */
     $this->assertEquals($expect, $actual);
 }
示例#3
0
 /**
  * process
  *
  * @since 2.6.0
  */
 public static function _process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     $emailValidator = new Validator\Email();
     $urlValidator = new Validator\Url();
     $captchaValidator = new Validator\Captcha();
     /* process post */
     $postData = array('author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution'));
     /* validate post */
     if (!$postData['author']) {
         $errorData['author'] = Language::get('author_empty');
     }
     if (!$postData['email']) {
         $errorData['email'] = Language::get('email_empty');
     } else {
         if ($emailValidator->validate($postData['email']) === Validator\ValidatorInterface::FAILED) {
             $errorData['email'] = Language::get('email_incorrect');
         }
     }
     if ($errorData['url'] && $urlValidator->validate($postData['url']) === Validator\ValidatorInterface::FAILED) {
         $errorData['url'] = Language::get('url_incorrect');
     }
     if (!$postData['text']) {
         $errorData['text'] = Language::get('message_empty');
     }
     if ($captchaValidator->validate($postData['task'], $postData['solution']) === Validator\ValidatorInterface::FAILED) {
         $errorData['captcha'] = Language::get('captcha_incorrect');
     }
     /* handle error */
     if ($errorData) {
         notification(Language::get('error_occurred'), $errorData, Language::get('home'), Registry::get('root'));
     } else {
         notification(Language::get('operation_completed'), Language::get('message_sent', '_contact'), Language::get('home'), Registry::get('root'));
         self::_send($postData);
     }
 }
示例#4
0
 /**
  * validate
  *
  * @since 3.0.0
  *
  * @param array $postArray array of the post
  *
  * @return array
  */
 protected function _validate($postArray = [])
 {
     $loginValidator = new Validator\Login();
     $emailValidator = new Validator\Email();
     $captchaValidator = new Validator\Captcha();
     /* validate post */
     $messageArray = [];
     if (!$postArray['name']) {
         $messageArray[] = $this->_language->get('name_empty');
     }
     if (!$postArray['user']) {
         $messageArray[] = $this->_language->get('user_empty');
     } else {
         if ($loginValidator->validate($postArray['user']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('user_incorrect');
         } else {
             if (Db::forTablePrefix('users')->where('user', $postArray['user'])->findOne()->id) {
                 $messageArray[] = $this->_language->get('user_exists');
             }
         }
     }
     if (!$postArray['email']) {
         $messageArray[] = $this->_language->get('email_empty');
     } else {
         if ($emailValidator->validate($postArray['email']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('email_incorrect');
         }
     }
     if (Db::getSetting('captcha') > 0 && $captchaValidator->validate($postArray['task'], $postArray['solution']) === Validator\ValidatorInterface::FAILED) {
         $messageArray[] = $this->_language->get('captcha_incorrect');
     }
     return $messageArray;
 }
示例#5
0
 /**
  * validate
  *
  * @since 3.0.0
  *
  * @param array $postArray array of the post
  * @param object $user object of the user
  *
  * @return array
  */
 protected function _validate($postArray = [], $user = null)
 {
     $captchaValidator = new Validator\Captcha();
     /* validate post */
     $messageArray = [];
     if (!$postArray['id']) {
         $messageArray[] = $this->_language->get('user_empty');
     } else {
         if (!$user->id) {
             $messageArray[] = $this->_language->get('user_incorrect');
         }
     }
     if (!$postArray['password']) {
         $messageArray[] = $this->_language->get('password_empty');
     } else {
         if (sha1($user->password) !== $postArray['password']) {
             $messageArray[] = $this->_language->get('password_incorrect');
         }
     }
     if ($captchaValidator->validate($postArray['task'], $postArray['solution']) === Validator\ValidatorInterface::FAILED) {
         $messageArray[] = $this->_language->get('captcha_incorrect');
     }
     return $messageArray;
 }
示例#6
0
 /**
  * validate
  *
  * @since 3.0.0
  *
  * @param array $postArray array of the post
  *
  * @return array
  */
 protected function _validate($postArray = [])
 {
     $emailValidator = new Validator\Email();
     $captchaValidator = new Validator\Captcha();
     $urlValidator = new Validator\Url();
     /* validate post */
     $messageArray = [];
     if (!$postArray['author']) {
         $messageArray[] = $this->_language->get('author_empty');
     }
     if (!$postArray['email']) {
         $messageArray[] = $this->_language->get('email_empty');
     } else {
         if ($emailValidator->validate($postArray['email']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('email_incorrect');
         }
     }
     if ($postArray['url'] && $urlValidator->validate($postArray['url']) === Validator\ValidatorInterface::FAILED) {
         $messageArray[] = $this->_language->get('url_incorrect');
     }
     if (!$postArray['text']) {
         $messageArray[] = $this->_language->get('comment_empty');
     }
     if (!$postArray['article']) {
         $messageArray[] = $this->_language->get('input_incorrect');
     }
     if (Db::getSetting('captcha') > 0 && $captchaValidator->validate($postArray['task'], $postArray['solution']) === Validator\ValidatorInterface::FAILED) {
         $messageArray[] = $this->_language->get('captcha_incorrect');
     }
     return $messageArray;
 }