bludit/bl-kernel/admin/controllers/login.php

78 lines
2.0 KiB
PHP
Raw Normal View History

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 $L;
2015-08-18 04:02:19 +02:00
if ($security->isBlocked()) {
Alert::set($L->g('IP address has been blocked').'<br>'.$L->g('Try again in a few minutes'), ALERT_STATUS_FAIL);
2015-08-18 04:02:19 +02:00
return false;
}
if ($login->verifyUser($_POST['username'], $_POST['password'])) {
2017-11-07 00:18:16 +01:00
if (isset($_POST['remember'])) {
$login->setRememberMe($_POST['username']);
2017-11-07 00:18:16 +01:00
}
2015-09-08 02:51:48 +02:00
// Renew the token. This token will be the same inside the session for multiple forms.
$security->generateTokenCSRF();
2018-07-25 23:42:00 +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();
// Create alert
Alert::set($L->g('Username or password incorrect'), ALERT_STATUS_FAIL);
2015-08-18 04:02:19 +02:00
return false;
}
2017-11-07 00:18:16 +01:00
function checkRememberMe()
{
global $security;
global $login;
2017-11-07 00:18:16 +01:00
if ($security->isBlocked()) {
2017-11-07 00:18:16 +01:00
return false;
}
if ($login->verifyUserByRemember()) {
$security->generateTokenCSRF();
2017-11-07 00:18:16 +01:00
Redirect::page('dashboard');
return true;
}
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
// ============================================================================