Advertisement
Guest User

Untitled

a guest
Dec 7th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1.        /** Проверка капчи. */
  2.         if($this->config->get('captcha.gregwar') == true and $this->request->isMethod('POST') == true) {
  3.             if($user != false) {
  4.                 $lastCaptchaDate = $user->getLastCaptchaDate();
  5.                 $newCaptchaDate = new \DateTime();
  6.                 $intervalCaptchaDate = $lastCaptchaDate->diff($newCaptchaDate);
  7.                 if($this->config->get('captcha.interval.hour') == 0) {
  8.                     $hoursCaptcha = 0;
  9.                 } else {
  10.                     $hoursCaptcha = $intervalCaptchaDate->format('%h');
  11.                 }
  12.                 if($this->config->get('captcha.interval.minutes') == 0) {
  13.                     $minutesCaptcha = 0;
  14.                 } else {
  15.                     $minutesCaptcha = $intervalCaptchaDate->format('%i');
  16.                 }
  17.             }
  18.             if(
  19.                 (!isset($hoursCaptcha) and !isset($minutesCaptcha)) or
  20.                 $hoursCaptcha * 60 + $minutesCaptcha < $this->config->get('captcha.interval.hour') * 60 + $this->config->get('captcha.interval.minutes')
  21.                 or $this->config->get('captcha.interval_on') != true)
  22.             {
  23.                 if(!isset($_POST['gregwar_captcha_value'])) {
  24.                     return $this->response->error($this->translator->trans('Не отправлена капча.'));
  25.                 }
  26.                 if ($this->captchaSession->check($_POST['gregwar_captcha_value']) == true) {
  27.                     $this->captchaSession->delete();
  28.                     /** Создание профиля пользователя. */
  29.                     if($user == false) {
  30.                         $user = new User;
  31.                         $userPassword = $this->password->random();
  32.                         $user->setPassword($this->password->hash($userPassword));
  33.                         $user->setPostsCount(0);
  34.                         $user->setVerifiedPostsCount(0);
  35.                         $user->setLastCaptchaDate(new \DateTime);
  36.                         $this->userRepository->save($user);
  37.                         /** Отправка cookie пользователю. */
  38.                         if($this->auth->getAnonymous() == false) {
  39.                             $this->cookie->setUser($user->getId(), $userPassword);
  40.                         }
  41.                     } else {
  42.                         $user->setLastCaptchaDate(new \Datetime);
  43.                         $this->userRepository->save($user);
  44.                     }
  45.                 } else {
  46.                     return $this->response->error($this->translator->trans('Неправильно введена капча.'));
  47.                 }
  48.             }
  49.         } else {
  50.             $user = new User;
  51.             $userPassword = $this->password->random();
  52.             $user->setPassword($this->password->hash($userPassword));
  53.             $user->setPostsCount(0);
  54.             $user->setVerifiedPostsCount(0);
  55.             $user->setLastCaptchaDate(new \DateTime);
  56.             $this->userRepository->save($user);
  57.             /** Отправка cookie пользователю. */
  58.             if($this->auth->getAnonymous() == false) {
  59.                 $this->cookie->setUser($user->getId(), $userPassword);
  60.             }
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement