1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/15564] Switch to Invisible reCAPTCHA

PHPBB3-15564
This commit is contained in:
Jakub Senko
2018-02-18 15:04:37 +01:00
committed by Marc Alexander
parent a90f5e6bcc
commit 760a03fffc
2 changed files with 58 additions and 26 deletions

View File

@@ -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();
}