Projet

Général

Profil

Révision e326068a

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/recaptcha/recaptcha.module
80 80
      if ($captcha_type == 'reCAPTCHA') {
81 81
        $recaptcha_site_key = variable_get('recaptcha_site_key', '');
82 82
        $recaptcha_secret_key = variable_get('recaptcha_secret_key', '');
83
        $recaptcha_use_globally = variable_get('recaptcha_use_globally', FALSE);
83 84

  
84 85
        if (!empty($recaptcha_site_key) && !empty($recaptcha_secret_key)) {
85 86
          // Build the reCAPTCHA captcha form if site_key and secret_key are
......
91 92
            '#value' => 'Google no captcha',
92 93
          );
93 94

  
95
          // As the validate callback does not depend on sid or solution, this
96
          // captcha type can be displayed on cached pages.
97
          $captcha['cacheable'] = TRUE;
98

  
99
          // Check if reCAPTCHA use globally is enabled.
100
          $recaptcha_src = 'https://www.google.com/recaptcha/api.js';
101
          $recaptcha_src_fallback = 'https://www.google.com/recaptcha/api/fallback';
102
          if ($recaptcha_use_globally) {
103
            $recaptcha_src = 'https://www.recaptcha.net/recaptcha/api.js';
104
            $recaptcha_src_fallback = 'https://www.recaptcha.net/recaptcha/api/fallback';
105
          }
106

  
94 107
          $noscript = '';
95 108
          if (variable_get('recaptcha_noscript', 0)) {
96 109
            $variables = array(
97 110
              'sitekey' => $recaptcha_site_key,
98 111
              'language' => $language->language,
112
              'recaptcha_src_fallback' => $recaptcha_src_fallback
99 113
            );
100 114
            $noscript = theme('recaptcha_widget_noscript', array('widget' => $variables));
101 115
          }
......
122 136
            '#tag' => 'script',
123 137
            '#value' => '',
124 138
            '#attributes' => array(
125
              'src' => url('https://www.google.com/recaptcha/api.js', array('query' => array('hl' => $language->language), 'absolute' => TRUE)),
139
              'src' => url($recaptcha_src, array('query' => array('hl' => $language->language), 'absolute' => TRUE)),
126 140
              'async' => 'async',
127 141
              'defer' => 'defer',
128 142
            ),
......
150 164
  // Use drupal_http_request() to circumvent all issues with the Google library.
151 165
  $recaptcha = new \ReCaptcha\ReCaptcha($recaptcha_secret_key, new \ReCaptcha\RequestMethod\Drupal7Post());
152 166

  
167
  // Ensures the hostname matches. Required if "Domain Name Validation" is
168
  // disabled for credentials.
169
  if (variable_get('recaptcha_verify_hostname', FALSE)) {
170
    $recaptcha->setExpectedHostname($_SERVER['SERVER_NAME']);
171
  }
172

  
153 173
  $resp = $recaptcha->verify(
154 174
    $_POST['g-recaptcha-response'],
155 175
    ip_address()
......
162 182
  else {
163 183
    // Error code reference, https://developers.google.com/recaptcha/docs/verify
164 184
    $error_codes = array(
165
      'missing-input-secret' => t('The secret parameter is missing.'),
166
      'invalid-input-secret' => t('The secret parameter is invalid or malformed.'),
167
      'missing-input-response' => t('The response parameter is missing.'),
185
      'action-mismatch' => t('Expected action did not match.'),
186
      'apk_package_name-mismatch' => t('Expected APK package name did not match.'),
187
      'bad-response' => t('Did not receive a 200 from the service.'),
188
      'bad-request' => t('The request is invalid or malformed.'),
189
      'challenge-timeout' => t('Challenge timeout.'),
190
      'connection-failed' => t('Could not connect to service.'),
168 191
      'invalid-input-response' => t('The response parameter is invalid or malformed.'),
192
      'invalid-input-secret' => t('The secret parameter is invalid or malformed.'),
169 193
      'invalid-json' => t('The json response is invalid or malformed.'),
170
      'unknown' => t('Unknown error.'),
194
      'missing-input-response' => t('The response parameter is missing.'),
195
      'missing-input-secret' => t('The secret parameter is missing.'),
196
      'hostname-mismatch' => t('Expected hostname did not match.'),
197
      'score-threshold-not-met' => t('Score threshold not met.'),
198
      'timeout-or-duplicate' => t('The challenge response timed out or was already verified.'),
199
      'unknown-error' => t('Not a success, but no error codes received!'),
171 200
    );
172 201
    foreach ($resp->getErrorCodes() as $code) {
173 202
      if (!isset($error_codes[$code])) {
174
        $code = 'unknown';
203
        $code = 'unknown-error';
175 204
      }
176 205
      watchdog('reCAPTCHA web service', '@error', array('@error' => $error_codes[$code]), WATCHDOG_ERROR);
177 206
    }
......
187 216
function template_preprocess_recaptcha_widget_noscript(&$variables) {
188 217
  $variables['sitekey']  = check_plain($variables['widget']['sitekey']);
189 218
  $variables['language'] = check_plain($variables['widget']['language']);
190
  $variables['url']      = check_url(url('https://www.google.com/recaptcha/api/fallback', array('query' => array('k' => $variables['widget']['sitekey'], 'hl' => $variables['widget']['language']), 'absolute' => TRUE)));
219
  $variables['url'] = check_url(url($variables['widget']['recaptcha_src_fallback'], array('query' => array('k' => $variables['widget']['sitekey'], 'hl' => $variables['widget']['language']), 'absolute' => TRUE)));
191 220
}

Formats disponibles : Unified diff