From 760a03fffc84b625a85d43bacd308cad35a668f0 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Sun, 18 Feb 2018 15:04:37 +0100 Subject: [PATCH 1/9] [ticket/15564] Switch to Invisible reCAPTCHA PHPBB3-15564 --- phpBB/assets/javascript/core.js | 53 +++++++++++++++++++ .../prosilver/template/captcha_recaptcha.html | 31 ++--------- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 2ce20a3b1a..c97eb4134a 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -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(); +} diff --git a/phpBB/styles/prosilver/template/captcha_recaptcha.html b/phpBB/styles/prosilver/template/captcha_recaptcha.html index a123f543a8..8fc7faa50f 100644 --- a/phpBB/styles/prosilver/template/captcha_recaptcha.html +++ b/phpBB/styles/prosilver/template/captcha_recaptcha.html @@ -1,30 +1,9 @@ - -
-
- -

{L_CONFIRMATION}

-

{L_CONFIRM_EXPLAIN}

- -
- - -
-

{L_RECAPTCHA_EXPLAIN}
-
- - -
-
-
+ + {% INCLUDEJS RECAPTCHA_SERVER ~ '.js?onload=phpbbRecaptchaOnLoad&hl=' ~ lang('RECAPTCHA_LANG') %} +
{L_RECAPTCHA_NOT_AVAILABLE} - - -
-
-
- From 0f3559528abb107c542050f592c1de4fef10e693 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Tue, 20 Feb 2018 08:40:24 +0100 Subject: [PATCH 2/9] [ticket/15564] Use es2015 PHPBB3-15564 --- phpBB/assets/javascript/core.js | 46 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index c97eb4134a..2dc3ac27d1 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1650,47 +1650,39 @@ phpbb.lazyLoadAvatars = function loadAvatars() { }); }; -// reCAPTCHA-related variables -var recaptcha_form = $('.g-recaptcha').parents('form'), - submit_button = null, - programatically_submitted = false; +const recaptchaForm = $('.g-recaptcha').parents('form'); +let submitButton = null; +let programaticallySubmitted = false; -/** - * Function is called when reCAPTCHA code is loaded - */ -phpbb.recaptchaOnLoad = function() { +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; + // Listen to submit buttons in order to know which one was pressed + $('input[type="submit"]').each(() => { + $(this).on('click', () => { + submitButton = this; }); }); - recaptcha_form.on('submit', function(e) { - if (!programatically_submitted) { + recaptchaForm.on('submit', e => { + if (!programaticallySubmitted) { 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), +phpbb.recaptchaOnSubmit = function () { + programaticallySubmitted = true; + // If concrete button was clicked (e.g. preview instead of submit), // let's trigger the same action - if (submit_button) { - submit_button.click(); + if (submitButton) { + submitButton.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'; + // Rename input[name="submit"] so that we can submit the form + if (typeof recaptchaForm.submit !== 'function') { + recaptchaForm.submit.name = 'submit_btn'; } - recaptcha_form.submit(); + recaptchaForm.submit(); } } From c0e9ef21fe5c6d79857c4dc8d2a527f986b40d51 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Tue, 20 Feb 2018 08:51:34 +0100 Subject: [PATCH 3/9] [ticket/15564] Update ACP as well PHPBB3-15564 --- phpBB/adm/style/captcha_recaptcha.html | 3 ++- phpBB/language/en/captcha_recaptcha.php | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/phpBB/adm/style/captcha_recaptcha.html b/phpBB/adm/style/captcha_recaptcha.html index 3f61c76cb1..563bd98835 100644 --- a/phpBB/adm/style/captcha_recaptcha.html +++ b/phpBB/adm/style/captcha_recaptcha.html @@ -5,8 +5,9 @@
{L_RECAPTCHA_NOSCRIPT}
+ {L_RECAPTCHA_INVISIBLE} -
+
diff --git a/phpBB/language/en/captcha_recaptcha.php b/phpBB/language/en/captcha_recaptcha.php index dde2a4ba08..db28820747 100644 --- a/phpBB/language/en/captcha_recaptcha.php +++ b/phpBB/language/en/captcha_recaptcha.php @@ -43,10 +43,10 @@ $lang = array_merge($lang, array( 'RECAPTCHA_INCORRECT' => 'The solution you provided was incorrect', 'RECAPTCHA_NOSCRIPT' => 'Please enable JavaScript in your browser to load the challenge.', - 'RECAPTCHA_PUBLIC' => 'Public reCaptcha key', - 'RECAPTCHA_PUBLIC_EXPLAIN' => 'Your public reCaptcha key. Keys can be obtained on www.google.com/recaptcha.', - 'RECAPTCHA_PRIVATE' => 'Private reCaptcha key', - 'RECAPTCHA_PRIVATE_EXPLAIN' => 'Your private reCaptcha key. Keys can be obtained on www.google.com/recaptcha.', + 'RECAPTCHA_PUBLIC' => 'Site key', + 'RECAPTCHA_PUBLIC_EXPLAIN' => 'Your site reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use Invisible reCAPTCHA type.', + 'RECAPTCHA_PRIVATE' => 'Secret key', + 'RECAPTCHA_PRIVATE_EXPLAIN' => 'Your secret reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use Invisible reCAPTCHA type.', - 'RECAPTCHA_EXPLAIN' => 'In an effort to prevent automatic submissions, we require that you complete the following challenge.', + 'RECAPTCHA_INVISIBLE' => 'This CAPTCHA is actually invisible. To verify that it works, a small icon should appear in right bottom corner of this page.', )); From 27153d7e46a0a6ec5e53d68799f4349e5be82276 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Tue, 27 Mar 2018 11:45:58 +0200 Subject: [PATCH 4/9] [ticket/15564] Remove console.log() call PHPBB3-15564 --- phpBB/assets/javascript/core.js | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 2dc3ac27d1..aa6fc7a37f 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1655,7 +1655,6 @@ let submitButton = null; let programaticallySubmitted = false; phpbb.recaptchaOnLoad = function () { - console.log('ahoj'); // Listen to submit buttons in order to know which one was pressed $('input[type="submit"]').each(() => { $(this).on('click', () => { From 772e801d4fb79c93555ebc451f8d646db4cc068e Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Wed, 4 Apr 2018 11:20:21 +0200 Subject: [PATCH 5/9] [ticket/15564] Don't use ES2015, it breaks UI tests PHPBB3-15564 --- phpBB/assets/javascript/core.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index aa6fc7a37f..fc8fe16d5f 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1650,19 +1650,19 @@ phpbb.lazyLoadAvatars = function loadAvatars() { }); }; -const recaptchaForm = $('.g-recaptcha').parents('form'); -let submitButton = null; -let programaticallySubmitted = false; +var recaptchaForm = $('.g-recaptcha').parents('form'); +var submitButton = null; +var programaticallySubmitted = false; phpbb.recaptchaOnLoad = function () { // Listen to submit buttons in order to know which one was pressed - $('input[type="submit"]').each(() => { - $(this).on('click', () => { + $('input[type="submit"]').each(function () { + $(this).on('click', function () { submitButton = this; }); }); - recaptchaForm.on('submit', e => { + recaptchaForm.on('submit', function (e) { if (!programaticallySubmitted) { grecaptcha.execute(); e.preventDefault(); From a05d74426667cc99b1e10d6f00c527519a250779 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 5 Apr 2018 08:03:35 +0200 Subject: [PATCH 6/9] [ticket/15564] Move JS functions closer to related code PHPBB3-15564 --- phpBB/assets/javascript/core.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index fc8fe16d5f..58016c872f 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1685,6 +1685,15 @@ phpbb.recaptchaOnSubmit = function () { } } +// 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(); +} + $(window).on('load', phpbb.lazyLoadAvatars); /** @@ -1717,12 +1726,3 @@ $(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(); -} From 25d3292d30683e00e315586643f36f44c492a8dc Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Mon, 15 Oct 2018 08:23:29 +0200 Subject: [PATCH 7/9] [ticket/15564] Move recaptcha callbacks to global space PHPBB3-15564 --- phpBB/assets/javascript/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 58016c872f..bb38441622 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1687,10 +1687,10 @@ phpbb.recaptchaOnSubmit = function () { // reCAPTCHA doesn't accept callback functions nested inside objects // so we need to make this helper functions here -function phpbbRecaptchaOnLoad() { +window.phpbbRecaptchaOnLoad = function() { phpbb.recaptchaOnLoad(); } -function phpbbRecaptchaOnSubmit() { +window.phpbbRecaptchaOnSubmit = function() { phpbb.recaptchaOnSubmit(); } From d7dd91d0e25638373c57c9813f4c7b13deff84c3 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Fri, 24 May 2019 09:58:44 +0200 Subject: [PATCH 8/9] [ticket/15564] Improve wording since captcha can be invisible now PHPBB3-15564 --- phpBB/language/en/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index f77cf0c0c8..5f47fbe6ed 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -392,7 +392,7 @@ $lang = array_merge($lang, array( 'LOGIN_CHECK_PM' => 'Log in to check your private messages.', 'LOGIN_CONFIRMATION' => 'Confirmation of login', 'LOGIN_CONFIRM_EXPLAIN' => 'To prevent brute forcing accounts the board requires you to enter a confirmation code after a maximum amount of failed logins. The code is displayed in the image you should see below. If you are visually impaired or cannot otherwise read this code please contact the %sBoard Administrator%s.', // unused - 'LOGIN_ERROR_ATTEMPTS' => 'You exceeded the maximum allowed number of login attempts. In addition to your username and password you now also have to solve the CAPTCHA below.', + 'LOGIN_ERROR_ATTEMPTS' => 'You exceeded the maximum allowed number of login attempts. In addition to your username and password you now also have to pass the CAPTCHA test.', 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE' => 'You have not been authenticated by Apache.', 'LOGIN_ERROR_OAUTH_SERVICE_DOES_NOT_EXIST' => 'A non-existant OAuth service has been requested.', 'LOGIN_ERROR_PASSWORD' => 'You have specified an incorrect password. Please check your password and try again. If you continue to have problems please contact the %sBoard Administrator%s.', From 7fac5be2cceff962357c0a6dac900380d2cc603f Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Mon, 29 Jul 2019 08:27:29 +0200 Subject: [PATCH 9/9] [ticket/15564] Improve wording PHPBB3-15564 --- phpBB/language/en/captcha_recaptcha.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/language/en/captcha_recaptcha.php b/phpBB/language/en/captcha_recaptcha.php index db28820747..68546ae73c 100644 --- a/phpBB/language/en/captcha_recaptcha.php +++ b/phpBB/language/en/captcha_recaptcha.php @@ -44,9 +44,9 @@ $lang = array_merge($lang, array( 'RECAPTCHA_NOSCRIPT' => 'Please enable JavaScript in your browser to load the challenge.', 'RECAPTCHA_PUBLIC' => 'Site key', - 'RECAPTCHA_PUBLIC_EXPLAIN' => 'Your site reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use Invisible reCAPTCHA type.', + 'RECAPTCHA_PUBLIC_EXPLAIN' => 'Your site reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use reCAPTCHA v2 > Invisible reCAPTCHA badge type.', 'RECAPTCHA_PRIVATE' => 'Secret key', - 'RECAPTCHA_PRIVATE_EXPLAIN' => 'Your secret reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use Invisible reCAPTCHA type.', + 'RECAPTCHA_PRIVATE_EXPLAIN' => 'Your secret reCAPTCHA key. Keys can be obtained on www.google.com/recaptcha. Please, use reCAPTCHA v2 > Invisible reCAPTCHA badge type.', 'RECAPTCHA_INVISIBLE' => 'This CAPTCHA is actually invisible. To verify that it works, a small icon should appear in right bottom corner of this page.', ));