|
1 | 1 | <?php |
2 | 2 | $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
3 | 3 |
|
| 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 | + |
4 | 16 | // 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) { |
7 | 18 | if (!empty($_POST['username']) && !empty($_POST['password'])) { |
8 | 19 | // 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"]); |
18 | 23 | } |
19 | 24 | } |
20 | 25 |
|
|
23 | 28 | $_SESSION['POPUP'][] = array('CONTENT' => 'You are not allowed to login during maintenace.', 'TYPE' => 'alert alert-info'); |
24 | 29 | } else { |
25 | 30 | // 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) { |
27 | 32 | if (!$config['csrf']['enabled'] || $config['csrf']['enabled'] && $csrftoken->valid) { |
28 | 33 | // check if login is correct |
29 | 34 | if ($user->checkLogin(@$_POST['username'], @$_POST['password']) ) { |
|
0 commit comments