Skip to content

Commit 97b3cc3

Browse files
authored
Merge pull request #2692 from AmazingDreams/development
Cleaner recaptcha v2
2 parents 145304b + 4180bf1 commit 97b3cc3

File tree

9 files changed

+64
-306
lines changed

9 files changed

+64
-306
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
"email": "delboy1978uk@gmail.com"
1111
}
1212
],
13-
"require": {}
13+
"require": {
14+
"google/recaptcha": "~1.1"
15+
}
1416
}

composer.phar

1.78 MB
Binary file not shown.

include/autoloader.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(SECURITY == "*)WT#&YHfd" && SECHASH_CHECK) ? die("public/index.php -> Set a new SECURITY value to continue") : 0;
33
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
44

5+
require_once(INCLUDE_DIR . '/../vendor/autoload.php');
6+
57
// Default classes
68
require_once(INCLUDE_DIR . '/lib/KLogger.php');
79
require_once(CLASS_DIR . '/logger.class.php');

include/lib/recaptchalib.php

Lines changed: 0 additions & 274 deletions
This file was deleted.

include/pages/login.inc.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
<?php
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

4+
$recaptcha_enabled = ($setting->getValue('recaptcha_enabled') && $setting->getValue('recaptcha_enabled_logins'));
5+
6+
if ($recaptcha_enabled) {
7+
$recaptcha_secret = $setting->getValue('recaptcha_private_key');
8+
$recaptcha_public_key = $setting->getValue('recaptcha_public_key');
9+
10+
$recaptcha = new \ReCaptcha\ReCaptcha($recaptcha_secret);
11+
$smarty->assign("recaptcha_public_key", $recaptcha_public_key);
12+
}
13+
14+
$smarty->assign("recaptcha_enabled", $recaptcha_enabled);
15+
416
// ReCaptcha handling if enabled
5-
if ($setting->getValue('recaptcha_enabled') && $setting->getValue('recaptcha_enabled_logins')) {
6-
require_once(INCLUDE_DIR . '/lib/recaptchalib.php');
17+
if ($recaptcha_enabled) {
718
if (!empty($_POST['username']) && !empty($_POST['password'])) {
819
// Load re-captcha specific data
9-
$rsp = recaptcha_check_answer (
10-
$setting->getValue('recaptcha_private_key'),
11-
$_SERVER["REMOTE_ADDR"],
12-
( (isset($_POST["recaptcha_challenge_field"])) ? $_POST["recaptcha_challenge_field"] : null ),
13-
( (isset($_POST["recaptcha_response_field"])) ? $_POST["recaptcha_response_field"] : null )
14-
);
15-
$smarty->assign("RECAPTCHA", recaptcha_get_html($setting->getValue('recaptcha_public_key'), $rsp->error, true));
16-
} else {
17-
$smarty->assign("RECAPTCHA", recaptcha_get_html($setting->getValue('recaptcha_public_key'), null, true));
20+
21+
$recaptcha_response = (isset($_POST["g-recaptcha-response"]) ? $_POST["g-recaptcha-response"] : null);
22+
$rsp = $recaptcha->verify($recaptcha_response, $_SERVER["REMOTE_ADDRESS"]);
1823
}
1924
}
2025

@@ -23,7 +28,7 @@
2328
$_SESSION['POPUP'][] = array('CONTENT' => 'You are not allowed to login during maintenace.', 'TYPE' => 'alert alert-info');
2429
} else {
2530
// Check if recaptcha is enabled, process form data if valid
26-
if (!$setting->getValue('recaptcha_enabled') || !$setting->getValue('recaptcha_enabled_logins') || ($setting->getValue('recaptcha_enabled') && $setting->getValue('recaptcha_enabled_logins') && $rsp->is_valid)) {
31+
if (($recaptcha_enabled && $rsp->isSuccess()) || !$recaptcha_enabled) {
2732
if (!$config['csrf']['enabled'] || $config['csrf']['enabled'] && $csrftoken->valid) {
2833
// check if login is correct
2934
if ($user->checkLogin(@$_POST['username'], @$_POST['password']) ) {

include/pages/register.inc.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
$_SESSION['POPUP'][] = array('CONTENT' => 'Only invited users are allowed to register.', 'TYPE' => 'alert alert-danger');
99
$smarty->assign("CONTENT", "disabled.tpl");
1010
} else {
11-
if ($setting->getValue('recaptcha_enabled') && $setting->getValue('recaptcha_enabled_registrations')) {
12-
require_once(INCLUDE_DIR . '/lib/recaptchalib.php');
13-
$smarty->assign("RECAPTCHA", recaptcha_get_html($setting->getValue('recaptcha_public_key'), null, true));
11+
$recaptcha_enabled = ($setting->getValue('recaptcha_enabled') && $setting->getValue('recaptcha_enabled_registrations'));
12+
$smarty->assign("recaptcha_enabled", $recaptcha_enabled);
13+
14+
if ($recaptcha_enabled) {
15+
$recaptcha_public_key = $setting->getValue('recaptcha_public_key');
16+
$smarty->assign("recaptcha_public_key", $recaptcha_public_key);
1417
}
18+
1519
// Load news entries for Desktop site and unauthenticated users
1620
$smarty->assign("CONTENT", "default.tpl");
1721
}

0 commit comments

Comments
 (0)