С версии: 2.2.0
Автор: Henry Ruhs
Автор: Sven Weingartner
Наследование: implements Redaxscript\Validator\ValidatorInterface
Пример #1
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $emailValidator = new Validator\Email();
     $loginValidator = new Validator\Login();
     $auth = new Auth($this->_request);
     /* process post */
     $postArray = ['password' => $specialFilter->sanitize($this->_request->getPost('password')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* user and email */
     $users = Db::forTablePrefix('users');
     if ($emailValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) {
         $postArray['user'] = $emailFilter->sanitize($this->_request->getPost('user'));
         $users->where('email', $postArray['user']);
     } else {
         if ($loginValidator->validate($this->_request->getPost('user')) === Validator\ValidatorInterface::PASSED) {
             $postArray['user'] = $specialFilter->sanitize($this->_request->getPost('user'));
             $users->where('user', $postArray['user']);
         }
     }
     $user = $users->where('status', 1)->findOne();
     /* handle error */
     $messageArray = $this->_validate($postArray, $user);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     if ($auth->login($user->id)) {
         return $this->_success();
     }
     return $this->_error(['message' => $this->_language->get('something_wrong')]);
 }
Пример #2
0
 /**
  * testEmail
  *
  * @since 2.2.0
  *
  * @param string $email
  * @param integer $expect
  *
  * @dataProvider providerEmail
  */
 public function testEmail($email = null, $expect = null)
 {
     /* setup */
     $validator = new Validator\Email();
     /* actual */
     $actual = $validator->validate($email);
     /* 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 the account
  *
  * @since 3.0.0
  *
  * @param array $postArray array to be validated
  *
  * @return array
  */
 protected function _validateAccount($postArray = [])
 {
     $emailValidator = new Validator\Email();
     $loginValidator = new Validator\Login();
     /* validate post */
     $messageArray = [];
     if (!$postArray['adminName']) {
         $messageArray[] = $this->_language->get('name_empty');
     }
     if (!$postArray['adminUser']) {
         $messageArray[] = $this->_language->get('user_empty');
     } else {
         if ($loginValidator->validate($postArray['adminUser']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('user_incorrect');
         }
     }
     if (!$postArray['adminPassword']) {
         $messageArray[] = $this->_language->get('password_empty');
     } else {
         if ($loginValidator->validate($postArray['adminPassword']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('password_incorrect');
         }
     }
     if (!$postArray['adminEmail']) {
         $messageArray[] = $this->_language->get('email_empty');
     } else {
         if ($emailValidator->validate($postArray['adminEmail']) === Validator\ValidatorInterface::FAILED) {
             $messageArray[] = $this->_language->get('email_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;
 }