From c433b571b4eeb3758b1d0a3ebdf3a896050a3b64 Mon Sep 17 00:00:00 2001 From: Shreyas Sinha Date: Wed, 15 Feb 2017 18:23:36 +0530 Subject: [PATCH] Pass Google reCAPTCHA with the submit button Signed-off-by: Shreyas Sinha --- js/functions.js | 28 +++++++++++++++++++ .../plugins/auth/AuthenticationCookie.php | 3 +- .../plugin/auth/AuthenticationCookieTest.php | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/js/functions.js b/js/functions.js index 0a5dde8182..35b3b2487e 100644 --- a/js/functions.js +++ b/js/functions.js @@ -5022,6 +5022,34 @@ function toggleDatepickerIfInvalid($td, $input_field) { } } +/* + * Function to enable the 'Go' button on login. + */ +function login_go_button_enable() { + $('#input_go').prop('disabled', false); +} + +/* + * Function to disable the 'Go' button on login. + */ +function login_go_button_disable() { + $('#input_go').prop('disabled', true); +} + +/* + * Setting the 'Go' login button to disable if captcha is enabled. + */ +$(function () +{ + + var captcha = $('.g-recaptcha').attr('captcha'); + + if(captcha=='enabled'){ + login_go_button_disable(); + } + +}); + /** * Unbind all event handlers before tearing down a page */ diff --git a/libraries/plugins/auth/AuthenticationCookie.php b/libraries/plugins/auth/AuthenticationCookie.php index a26152fcca..604c99f324 100644 --- a/libraries/plugins/auth/AuthenticationCookie.php +++ b/libraries/plugins/auth/AuthenticationCookie.php @@ -228,7 +228,8 @@ class AuthenticationCookie extends AuthenticationPlugin echo ''; echo '
'; + , htmlspecialchars($GLOBALS['cfg']['CaptchaLoginPublicKey']) , + '" data-callback="login_go_button_enable" data-expired-callback="login_go_button_disable" captcha="enabled">'; } echo ' diff --git a/test/classes/plugin/auth/AuthenticationCookieTest.php b/test/classes/plugin/auth/AuthenticationCookieTest.php index 1b5bffb686..0ff79ab8b8 100644 --- a/test/classes/plugin/auth/AuthenticationCookieTest.php +++ b/test/classes/plugin/auth/AuthenticationCookieTest.php @@ -334,7 +334,7 @@ class AuthenticationCookieTest extends PMATestCase ); $this->assertContains( - '
', + '
', $result ); }