Since: 2.2.0
Author: Henry Ruhs
Inheritance: implements Redaxscript\Filter\FilterInterface
Example #1
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $emailFilter = new Filter\Email();
     /* process post */
     $postArray = ['email' => $emailFilter->sanitize($this->_request->getPost('email')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $messageArray = [];
     $users = Db::forTablePrefix('users')->where(['email' => $postArray['email'], 'status' => 1])->findMany();
     /* process users */
     foreach ($users as $user) {
         $mailArray = ['id' => $user->id, 'name' => $user->name, 'user' => $user->user, 'password' => $user->password, 'email' => $user->email];
         if ($this->_mail($mailArray)) {
             $messageArray[] = $user->name . $this->_language->get('colon') . ' ' . $this->_language->get('recovery_sent');
         }
     }
     if ($messageArray) {
         return $this->_success(['message' => $messageArray]);
     }
     return $this->_error(['message' => $this->_language->get('something_wrong')]);
 }
Example #2
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     /* process post */
     $postArray = ['name' => $specialFilter->sanitize($this->_request->getPost('name')), 'user' => $specialFilter->sanitize($this->_request->getPost('user')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init(uniqid());
     $createArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getHash(), 'email' => $postArray['email'], 'language' => $this->_registry->get('language'), 'groups' => Db::forTablePrefix('groups')->where('alias', 'members')->findOne()->id, 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getRaw(), 'email' => $postArray['email']];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_error(['message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['message' => Db::getSetting('verification') ? $this->_language->get('registration_verification') : $this->_language->get('registration_sent')]);
 }
Example #3
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')]);
 }
Example #4
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['author' => $specialFilter->sanitize($this->_request->getPost('author')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'url' => $urlFilter->sanitize($this->_request->getPost('url')), 'text' => $htmlFilter->sanitize($this->_request->getPost('text')), 'article' => $specialFilter->sanitize($this->_request->getPost('article')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     $route = build_route('articles', $postArray['article']);
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['route' => $route, 'message' => $messageArray]);
     }
     /* handle success */
     $createArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text'], 'language' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->language, 'article' => $postArray['article'], 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['email' => $postArray['email'], 'url' => $postArray['url'], 'route' => $route, 'author' => $postArray['author'], 'text' => $postArray['text'], 'article' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->title];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['route' => $route, 'message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_warning(['route' => $route, 'message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['route' => $route, 'timeout' => Db::getSetting('notification') ? 2 : 0, 'message' => Db::getSetting('moderation') ? $this->_language->get('comment_moderation') : $this->_language->get('comment_sent')]);
 }
Example #5
0
 /**
  * testEmail
  *
  * @since 2.2.0
  *
  * @param string $email
  * @param string $expect
  *
  * @dataProvider providerFilterEmail
  */
 public function testEmail($email = null, $expect = null)
 {
     /* setup */
     $filter = new Filter\Email();
     /* actual */
     $actual = $filter->sanitize($email);
     /* compare */
     $this->assertEquals($expect, $actual);
 }
Example #6
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     /* process post */
     $postArray = ['dbType' => $this->_request->getPost('db-type'), 'dbHost' => $this->_request->getPost('db-host'), 'dbName' => $this->_request->getPost('db-name'), 'dbUser' => $this->_request->getPost('db-user'), 'dbPassword' => $this->_request->getPost('db-password'), 'dbPrefix' => $this->_request->getPost('db-prefix'), 'dbSalt' => $this->_request->getPost('db-salt'), 'adminName' => $specialFilter->sanitize($this->_request->getPost('admin-name')), 'adminUser' => $specialFilter->sanitize($this->_request->getPost('admin-user')), 'adminPassword' => $specialFilter->sanitize($this->_request->getPost('admin-password')), 'adminEmail' => $emailFilter->sanitize($this->_request->getPost('admin-email')), 'refreshConnection' => $this->_request->getPost('refresh-connection')];
     /* handle error */
     $messageArray = $this->_validateDatabase($postArray);
     if ($messageArray) {
         return $this->_error(['url' => 'install.php', 'title' => $this->_language->get('database'), 'message' => $messageArray]);
     }
     $messageArray = $this->_validateAccount($postArray);
     if ($messageArray) {
         return $this->_error(['url' => 'install.php', 'title' => $this->_language->get('account'), 'message' => $messageArray]);
     }
     /* handle success */
     $configArray = ['dbType' => $postArray['dbType'], 'dbHost' => $postArray['dbHost'], 'dbName' => $postArray['dbName'], 'dbUser' => $postArray['dbUser'], 'dbPassword' => $postArray['dbPassword'], 'dbPrefix' => $postArray['dbPrefix'], 'dbSalt' => $postArray['dbSalt']];
     $adminArray = ['adminUser' => $postArray['adminUser'], 'adminName' => $postArray['adminName'], 'adminEmail' => $postArray['adminEmail'], 'adminPassword' => $postArray['adminPassword']];
     /* touch file */
     if ($configArray['dbType'] === 'sqlite' && !touch($configArray['dbHost']) && !unlink($configArray['dbHost'])) {
         return $this->_error(['url' => 'install.php', 'message' => $this->_language->get('directory_permission_grant') . $this->_language->get('point')]);
     }
     /* write config */
     if (!$this->_write($configArray)) {
         return $this->_error(['url' => 'install.php', 'message' => $this->_language->get('file_permission_grant') . $this->_language->get('colon') . ' config.php']);
     }
     /* refresh connection */
     if ($postArray['refreshConnection']) {
         $this->_refresh();
     }
     /* database status */
     if (!Db::getStatus()) {
         return $this->_error(['url' => 'install.php', 'message' => $this->_language->get('database_failed')]);
     }
     /* install */
     if (!$this->_install($adminArray)) {
         return $this->error(['url' => 'install.php', 'message' => $this->_language->get('installation_failed')]);
     }
     /* mail */
     if (!$this->_mail($adminArray)) {
         return $this->_warning(['url' => $this->_registry->get('root'), 'message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['url' => $this->_registry->get('root'), 'message' => $this->_language->get('installation_completed')]);
 }
Example #7
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['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')];
     /* handle error */
     $messageArray = self::_validate($postArray);
     if ($messageArray) {
         return self::_error(['message' => $messageArray]);
     }
     /* handle success */
     $mailArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text']];
     /* mail */
     if (self::_mail($mailArray)) {
         return self::_success();
     }
     return self::_error(['message' => Language::get('something_wrong')]);
 }
Example #8
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);
     }
 }