Skip to content

Commit

Permalink
Implement $cfg['CaptchaSiteVerifyURL'] for Google re-captcha
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 2, 2020
1 parent 85174fd commit 3278415
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions doc/config.rst
Expand Up @@ -1892,6 +1892,17 @@ Cookie authentication options

reCaptcha will be then used in :ref:`cookie`.

.. config:option:: $cfg['CaptchaSiteVerifyURL']
:type: string
:default: ``''``

The URL for the reCaptcha service to do siteverify action.

reCaptcha will be then used in :ref:`cookie`.

.. versionadded:: 5.1.0

Navigation panel setup
----------------------

Expand Down
2 changes: 2 additions & 0 deletions libraries/classes/Config/Descriptions.php
Expand Up @@ -898,6 +898,8 @@ public static function getString($path, $type = 'name')
'CaptchaLoginPublicKey_name' => __('Public key for reCaptcha'),
'CaptchaLoginPrivateKey_desc' => __('Enter your private key for your domain reCaptcha service.'),
'CaptchaLoginPrivateKey_name' => __('Private key for reCaptcha'),
'CaptchaSiteVerifyURL_desc' => __('Enter your siteverify URL for your reCaptcha service.'),
'CaptchaSiteVerifyURL_name' => __('URL for reCaptcha siteverify'),

'SendErrorReports_desc' => __('Choose the default action when sending error reports.'),
'SendErrorReports_name' => __('Send error reports'),
Expand Down
1 change: 1 addition & 0 deletions libraries/classes/Config/Forms/Setup/FeaturesForm.php
Expand Up @@ -49,6 +49,7 @@ public static function getForms()
'LoginCookieDeleteAll',
'CaptchaLoginPublicKey',
'CaptchaLoginPrivateKey',
'CaptchaSiteVerifyURL',
];
$result['Developer'] = [
'UserprefsDeveloperTab',
Expand Down
8 changes: 5 additions & 3 deletions libraries/classes/Plugins/Auth/AuthenticationCookie.php
Expand Up @@ -268,20 +268,22 @@ public function readCredentials()
&& ! empty($GLOBALS['cfg']['CaptchaLoginPublicKey'])
) {
if (! empty($_POST['g-recaptcha-response'])) {
$captchaSiteVerifyURL = $GLOBALS['cfg']['CaptchaSiteVerifyURL'] ?? '';
$captchaSiteVerifyURL = empty($captchaSiteVerifyURL) ? null : $captchaSiteVerifyURL;
if (function_exists('curl_init')) {
$reCaptcha = new ReCaptcha\ReCaptcha(
$GLOBALS['cfg']['CaptchaLoginPrivateKey'],
new ReCaptcha\RequestMethod\CurlPost()
new ReCaptcha\RequestMethod\CurlPost(null, $captchaSiteVerifyURL)
);
} elseif (ini_get('allow_url_fopen')) {
$reCaptcha = new ReCaptcha\ReCaptcha(
$GLOBALS['cfg']['CaptchaLoginPrivateKey'],
new ReCaptcha\RequestMethod\Post()
new ReCaptcha\RequestMethod\Post($captchaSiteVerifyURL)
);
} else {
$reCaptcha = new ReCaptcha\ReCaptcha(
$GLOBALS['cfg']['CaptchaLoginPrivateKey'],
new ReCaptcha\RequestMethod\SocketPost()
new ReCaptcha\RequestMethod\SocketPost(null, $captchaSiteVerifyURL)
);
}

Expand Down
7 changes: 7 additions & 0 deletions libraries/config.default.php
Expand Up @@ -848,6 +848,13 @@
*/
$cfg['CaptchaLoginPrivateKey'] = '';

/**
* if reCaptcha is enabled may need an URL for site verify
*
* @global string $cfg['CaptchaSiteVerifyURL']
*/
$cfg['CaptchaSiteVerifyURL'] = '';

/**
* Enable drag and drop import
*
Expand Down

0 comments on commit 3278415

Please sign in to comment.