Skip to content

Commit

Permalink
upgraded google recpatcha with google invisble recaptcha
Browse files Browse the repository at this point in the history
Signed-off-by: Manish Bisht <manish.bisht490@gmail.com>
  • Loading branch information
manishbisht committed Mar 21, 2017
1 parent aefe197 commit 53223d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
13 changes: 3 additions & 10 deletions js/functions.js
Expand Up @@ -5027,17 +5027,10 @@ function toggleDatepickerIfInvalid($td, $input_field) {
}

/*
* Function to enable the 'Go' button on login.
* Function to submit the login form after validation is done.
*/
function loginButtonEnable() {
$('#input_go').prop('disabled', false);
}

/*
* Function to disable the 'Go' button on login.
*/
function loginButtonDisable() {
$('#input_go').prop('disabled', true);
function recaptchaCallback() {
$('#login_form').submit();
}

/**
Expand Down
26 changes: 13 additions & 13 deletions libraries/plugins/auth/AuthenticationCookie.php
Expand Up @@ -170,7 +170,7 @@ public function auth()
echo '
<br />
<!-- Login form -->
<form method="post" action="index.php" name="login_form"' , $autocomplete ,
<form method="post" id="login_form" action="index.php" name="login_form"' , $autocomplete ,
' class="disableAjax login hide js-show">
<fieldset>
<legend>';
Expand Down Expand Up @@ -226,21 +226,21 @@ public function auth()
, $GLOBALS['server'] , '" />';
} // end if (server choice)

// Add captcha input field if reCaptcha is enabled
if (!empty($GLOBALS['cfg']['CaptchaLoginPrivateKey'])
&& !empty($GLOBALS['cfg']['CaptchaLoginPublicKey'])
echo '</fieldset><fieldset class="tblFooters">';

// binds input field with invisible reCaptcha if enabled
if (empty($GLOBALS['cfg']['CaptchaLoginPrivateKey'])
&& empty($GLOBALS['cfg']['CaptchaLoginPublicKey'])
) {
// If enabled show captcha to the user on the login screen.
echo '<input value="' , __('Go') , '" type="submit" id="input_go" />';
}
else {
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']) ,
'" data-callback="loginButtonEnable" data-expired-callback="loginButtonDisable" captcha="enabled"></div>';
, $GLOBALS['lang'] , '" async defer></script>';
echo '<input class="g-recaptcha" data-sitekey="'
, htmlspecialchars($GLOBALS['cfg']['CaptchaLoginPublicKey']),'"'
.' data-callback="recaptchaCallback" value="' , __('Go') , '" type="submit" id="input_go" />';
}

echo '</fieldset>
<fieldset class="tblFooters">
<input value="' , __('Go') , '" type="submit" id="input_go" />';
$_form_params = array();
if (! empty($GLOBALS['target'])) {
$_form_params['target'] = $GLOBALS['target'];
Expand Down
7 changes: 4 additions & 3 deletions test/classes/plugin/auth/AuthenticationCookieTest.php
Expand Up @@ -209,7 +209,7 @@ public function testAuthError()
);

$this->assertContains(
'<form method="post" action="index.php" name="login_form" ' .
'<form method="post" id="login_form" action="index.php" name="login_form" ' .
'class="disableAjax login hide js-show">',
$result
);
Expand Down Expand Up @@ -317,7 +317,7 @@ public function testAuthCaptcha()
}

$this->assertContains(
'<form method="post" action="index.php" name="login_form" ' .
'<form method="post" id="login_form" action="index.php" name="login_form" ' .
'autocomplete="off" class="disableAjax login hide js-show">',
$result
);
Expand All @@ -334,7 +334,8 @@ public function testAuthCaptcha()
);

$this->assertContains(
'<div class="g-recaptcha" data-sitekey="testpubkey" data-callback="loginButtonEnable" data-expired-callback="loginButtonDisable" captcha="enabled">',
'<input class="g-recaptcha" data-sitekey="testpubkey"'
. ' data-callback="recaptchaCallback" value="Go" type="submit" id="input_go" />',
$result
);
}
Expand Down

0 comments on commit 53223d3

Please sign in to comment.