Fixes for racaptcha

This commit is contained in:
slawkens 2022-11-28 12:41:29 +01:00
parent c73e476e88
commit 118e8c487e
6 changed files with 22 additions and 17 deletions

View File

@ -141,7 +141,7 @@ $config = array(
'recaptcha_site_key' => '', // get your own site and secret keys at https://www.google.com/recaptcha 'recaptcha_site_key' => '', // get your own site and secret keys at https://www.google.com/recaptcha
'recaptcha_secret_key' => '', 'recaptcha_secret_key' => '',
// following option apply only for ReCaptcha v2-checkbox // following option apply only for ReCaptcha v2-checkbox
'recaptcha_theme' => 'light', // light, dark 'recaptcha_v2_theme' => 'light', // light, dark
// following option apply only for ReCaptcha v3 // following option apply only for ReCaptcha v3
// min score for validation, between 0 - 1.0 // min score for validation, between 0 - 1.0
// https://developers.google.com/recaptcha/docs/v3#interpreting_the_score // https://developers.google.com/recaptcha/docs/v3#interpreting_the_score

View File

@ -41,18 +41,23 @@ class GoogleReCAPTCHA
} }
$json = json_decode($response); $json = json_decode($response);
$recaptchaType = config('recaptcha_type');
if ($recaptchaType === 'v3') { // score based
//log_append('recaptcha.log', 'recaptcha_score: ' . $json->score . ', action:' . $json->action); //log_append('recaptcha.log', 'recaptcha_score: ' . $json->score . ', action:' . $json->action);
if (!isset($json->action) || $json->action !== $action) { if (!isset($json->action) || $json->action !== $action) {
self::$errorType = self::ERROR_INVALID_ACTION; self::$errorType = self::ERROR_INVALID_ACTION;
self::$errorMessage = 'Google ReCaptcha returned invalid action.'; self::$errorMessage = 'Google ReCaptcha returned invalid action.';
return false; return false;
} }
if (!isset($json->score) || $json->score < config('recaptcha_min_score')) { if (!isset($json->score) || $json->score < config('recaptcha_v3_min_score')) {
self::$errorType = self::ERROR_LOW_SCORE; self::$errorType = self::ERROR_LOW_SCORE;
self::$errorMessage = 'Your Google ReCaptcha score was too low.'; self::$errorMessage = 'Your Google ReCaptcha score was too low.';
return false; return false;
} }
}
if (!isset($json->success) || !$json->success) { if (!isset($json->success) || !$json->success) {
self::$errorType = self::ERROR_NO_SUCCESS; self::$errorType = self::ERROR_NO_SUCCESS;

View File

@ -120,7 +120,7 @@
<span{% if errors.verification[0] is not null %} class="red"{% endif %}>Verification:</span> <span{% if errors.verification[0] is not null %} class="red"{% endif %}>Verification:</span>
</td> </td>
<td> <td>
<div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_theme }}"></div> <div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_v2_theme }}"></div>
</td> </td>
</tr> </tr>
{% if errors.verification is defined %} {% if errors.verification is defined %}

View File

@ -50,7 +50,7 @@ Please enter your account {{ account|lower }} and your password.<br/><a href="?s
<span{% if error is not null %} class="red"{% endif %}>Verification:</span> <span{% if error is not null %} class="red"{% endif %}>Verification:</span>
</td> </td>
<td> <td>
<div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_theme }}"></div> <div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_v2_theme }}"></div>
</td> </td>
</tr> </tr>
{% endif %} {% endif %}

View File

@ -17,5 +17,5 @@
</div> </div>
</noscript> </noscript>
{% if config.recaptcha_enabled %} {% if config.recaptcha_enabled %}
<script src="https://www.google.com/recaptcha/api.js?render={{ config.recaptcha_site_key }}"></script> <script src="https://www.google.com/recaptcha/api.js{% if config('recaptcha_type') === 'v2-checkbox' %}?render={{ config.recaptcha_site_key }}{% endif %}"></script>
{% endif %} {% endif %}

View File

@ -58,7 +58,7 @@
<span{% if error is not null %} class="red"{% endif %}>Verification:</span> <span{% if error is not null %} class="red"{% endif %}>Verification:</span>
</td> </td>
<td> <td>
<div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_theme }}"></div> <div class="g-recaptcha" data-sitekey="{{ config.recaptcha_site_key }}" data-theme="{{ config.recaptcha_v2_theme }}"></div>
</td> </td>
</tr> </tr>
{% endif %} {% endif %}