mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-15 05:14:28 +02:00
[ticket/15564] Switch to Invisible reCAPTCHA
PHPBB3-15564
This commit is contained in:
parent
a90f5e6bcc
commit
760a03fffc
@ -1650,6 +1650,50 @@ phpbb.lazyLoadAvatars = function loadAvatars() {
|
||||
});
|
||||
};
|
||||
|
||||
// reCAPTCHA-related variables
|
||||
var recaptcha_form = $('.g-recaptcha').parents('form'),
|
||||
submit_button = null,
|
||||
programatically_submitted = false;
|
||||
|
||||
/**
|
||||
* Function is called when reCAPTCHA code is loaded
|
||||
*/
|
||||
phpbb.recaptchaOnLoad = function() {
|
||||
console.log('ahoj');
|
||||
// listen to submit buttons in order to know which one was pressed
|
||||
$('input[type="submit"]').each(function() {
|
||||
$(this).on('click', function() {
|
||||
submit_button = this;
|
||||
});
|
||||
});
|
||||
|
||||
recaptcha_form.on('submit', function(e) {
|
||||
if (!programatically_submitted) {
|
||||
grecaptcha.execute();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function is called after successful solving of reCAPTCHA
|
||||
*/
|
||||
phpbb.recaptchaOnSubmit = function() {
|
||||
console.log('submit');
|
||||
programatically_submitted = true;
|
||||
// if concrete button was clicked (e.g. preview instead of submit),
|
||||
// let's trigger the same action
|
||||
if (submit_button) {
|
||||
submit_button.click();
|
||||
} else {
|
||||
// rename input[name="submit"] so that we can submit the form
|
||||
if (typeof recaptcha_form.submit !== 'function') {
|
||||
recaptcha_form.submit.name = 'submit_btn';
|
||||
}
|
||||
recaptcha_form.submit();
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on('load', phpbb.lazyLoadAvatars);
|
||||
|
||||
/**
|
||||
@ -1682,3 +1726,12 @@ $(function() {
|
||||
});
|
||||
|
||||
})(jQuery); // Avoid conflicts with other libraries
|
||||
|
||||
// reCAPTCHA doesn't accept callback functions nested inside objects
|
||||
// so we need to make this helper functions here
|
||||
function phpbbRecaptchaOnLoad() {
|
||||
phpbb.recaptchaOnLoad();
|
||||
}
|
||||
function phpbbRecaptchaOnSubmit() {
|
||||
phpbb.recaptchaOnSubmit();
|
||||
}
|
||||
|
@ -1,30 +1,9 @@
|
||||
<!-- IF S_TYPE == 1 -->
|
||||
<div class="panel captcha-panel">
|
||||
<div class="inner">
|
||||
|
||||
<h3 class="captcha-title">{L_CONFIRMATION}</h3>
|
||||
<p>{L_CONFIRM_EXPLAIN}</p>
|
||||
|
||||
<fieldset class="fields2">
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF S_RECAPTCHA_AVAILABLE -->
|
||||
<dl>
|
||||
<dt><label>{L_CONFIRM_CODE}{L_COLON}</label><br /><span>{L_RECAPTCHA_EXPLAIN}</span></dt>
|
||||
<dd class="captcha">
|
||||
<noscript>
|
||||
<div>{L_RECAPTCHA_NOSCRIPT}</div>
|
||||
</noscript>
|
||||
<script src="{RECAPTCHA_SERVER}.js?hl={LA_RECAPTCHA_LANG}" async defer></script>
|
||||
<div class="g-recaptcha" data-sitekey="{RECAPTCHA_PUBKEY}" data-tabindex="<!-- IF $CAPTCHA_TAB_INDEX -->{$CAPTCHA_TAB_INDEX}<!-- ELSE -->10<!-- ENDIF -->"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
<noscript>
|
||||
<div>{L_RECAPTCHA_NOSCRIPT}</div>
|
||||
</noscript>
|
||||
{% INCLUDEJS RECAPTCHA_SERVER ~ '.js?onload=phpbbRecaptchaOnLoad&hl=' ~ lang('RECAPTCHA_LANG') %}
|
||||
<div class="g-recaptcha" data-sitekey="{RECAPTCHA_PUBKEY}" data-callback="phpbbRecaptchaOnSubmit" data-size="invisible" data-tabindex="<!-- IF $CAPTCHA_TAB_INDEX -->{$CAPTCHA_TAB_INDEX}<!-- ELSE -->10<!-- ENDIF -->"></div>
|
||||
<!-- ELSE -->
|
||||
{L_RECAPTCHA_NOT_AVAILABLE}
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF S_TYPE == 1 -->
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user