/**
  * @param string $value
  * @return array|null
  * @throws Exception
  */
 protected function validateValue($value)
 {
     if (!Setting::get('recaptcha_secret')) {
         throw new InvalidConfigException('Required `recatpcha_secret` setting isn\'t set.');
     }
     if (empty($value)) {
         if (!($value = Yii::$app->request->post(self::CAPTCHA_RESPONSE_FIELD))) {
             return [$this->message, []];
         }
     }
     $request = self::SITE_VERIFY_URL . '?' . http_build_query(['secret' => Setting::get('recaptcha_secret'), 'response' => $value, 'remoteip' => Yii::$app->request->userIP]);
     $response = $this->getResponse($request);
     if (!isset($response['success'])) {
         throw new Exception('Invalid recaptcha verify response.');
     }
     return $response['success'] ? null : [$this->message, []];
 }
Exemple #2
0
 public function run()
 {
     $this->customFieldPrepare();
     $divOptions = ['class' => 'g-recaptcha', 'data-sitekey' => Setting::get('recaptcha_key')];
     if (empty($this->jsCallback)) {
         $divOptions['data-callback'] = $this->jsCallback;
     }
     if (empty($this->theme)) {
         $divOptions['data-theme'] = $this->theme;
     }
     if (empty($this->type)) {
         $divOptions['data-type'] = $this->type;
     }
     if (isset($this->widgetOptions['class'])) {
         $divOptions['class'] = "{$divOptions['class']} {$this->widgetOptions['class']}";
     }
     $divOptions = $divOptions + $this->widgetOptions;
     echo Html::tag('div', '', $divOptions);
 }