Skip to content

Commit

Permalink
Pass Google reCAPTCHA with the submit button
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Sinha <shreyas.sinha14@gmail.com>
  • Loading branch information
ShreyasSinha committed Feb 18, 2017
1 parent 3c5eaaf commit dc9284d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
28 changes: 28 additions & 0 deletions js/functions.js
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion libraries/plugins/auth/AuthenticationCookie.php
Expand Up @@ -228,7 +228,8 @@ public function auth()
echo '<script src="https://www.google.com/recaptcha/api.js?hl='
, $GLOBALS['lang'] , '" async defer></script>';
echo '<div class="g-recaptcha" data-sitekey="'
, htmlspecialchars($GLOBALS['cfg']['CaptchaLoginPublicKey']) , '"></div>';
, htmlspecialchars($GLOBALS['cfg']['CaptchaLoginPublicKey']) ,
'" data-callback="login_go_button_enable" data-expired-callback="login_go_button_disable" captcha="enabled"></div>';
}

echo '</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion test/classes/plugin/auth/AuthenticationCookieTest.php
Expand Up @@ -334,7 +334,7 @@ public function testAuthCaptcha()
);

$this->assertContains(
'<div class="g-recaptcha" data-sitekey="testpubkey">',
'<div class="g-recaptcha" data-sitekey="testpubkey" data-callback="login_go_button_enable" data-expired-callback="login_go_button_disable" captcha="enabled">',
$result
);
}
Expand Down

0 comments on commit dc9284d

Please sign in to comment.