2015-03-27 02:00:01 +01:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Check role
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-07-16 00:42:37 +02:00
|
|
|
function checkLogin($args)
|
2015-08-18 04:02:19 +02:00
|
|
|
{
|
|
|
|
global $Security;
|
|
|
|
global $Login;
|
|
|
|
global $Language;
|
|
|
|
|
2017-07-16 00:42:37 +02:00
|
|
|
if ($Security->isBlocked()) {
|
2015-08-18 04:02:19 +02:00
|
|
|
Alert::set($Language->g('IP address has been blocked').'<br>'.$Language->g('Try again in a few minutes'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-16 00:42:37 +02:00
|
|
|
if ($Login->verifyUser($_POST['username'], $_POST['password'])) {
|
2017-11-07 00:18:16 +01:00
|
|
|
if (isset($_POST['remember'])) {
|
|
|
|
$Login->setRememberMe($_POST['username']);
|
|
|
|
}
|
2015-09-08 02:51:48 +02:00
|
|
|
// Renew the token. This token will be the same inside the session for multiple forms.
|
2015-11-28 15:47:03 +01:00
|
|
|
$Security->generateTokenCSRF();
|
2017-06-05 22:36:09 +02:00
|
|
|
Redirect::page('dashboard');
|
2015-08-18 04:02:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-16 00:42:37 +02:00
|
|
|
// Bruteforce protection, add IP to the blacklist
|
|
|
|
$Security->addToBlacklist();
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
// Create alert
|
2015-08-18 04:02:19 +02:00
|
|
|
Alert::set($Language->g('Username or password incorrect'));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-07 00:18:16 +01:00
|
|
|
function checkRememberMe()
|
|
|
|
{
|
|
|
|
global $Security;
|
|
|
|
global $Login;
|
|
|
|
|
|
|
|
if ($Security->isBlocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-08 00:00:48 +01:00
|
|
|
if ($Login->verifyUserByRemember()) {
|
2017-11-07 00:18:16 +01:00
|
|
|
$Security->generateTokenCSRF();
|
|
|
|
Redirect::page('dashboard');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$Security->addToBlacklist();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Main before POST
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-11-07 00:18:16 +01:00
|
|
|
if ($_SERVER['REQUEST_METHOD']!=='POST') {
|
|
|
|
checkRememberMe();
|
|
|
|
}
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// POST Method
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-11-07 00:18:16 +01:00
|
|
|
if ($_SERVER['REQUEST_METHOD']=='POST') {
|
2017-07-16 00:42:37 +02:00
|
|
|
checkLogin($_POST);
|
2015-08-03 02:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Main after POST
|
2015-11-28 15:47:03 +01:00
|
|
|
// ============================================================================
|