Skip to content

Commit

Permalink
improv. auth perf (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkadax authored Jan 3, 2021
1 parent 03d5570 commit f537925
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 85 deletions.
67 changes: 41 additions & 26 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
class AppController extends Controller
{

var $components = array('Util', 'Module', 'Session', 'Cookie', 'Security', 'EyPlugin', 'Lang', 'Theme', 'History', 'Statistics', 'Permissions', 'Update', 'Server');
var $helpers = array('Session');
public $components = array('Util', 'Module', 'Session', 'Cookie', 'Security', 'EyPlugin', 'Lang', 'Theme', 'History', 'Statistics', 'Permissions', 'Update', 'Server');
public $helpers = array('Session');

var $view = 'Theme';
public $view = 'Theme';

protected $isConnected = false;

Expand Down Expand Up @@ -93,10 +93,23 @@ public function beforeFilter()
// lowercase to avoid errors when the controller is called with uppercase
$this->params['controller'] = strtolower($this->params['controller']);
$this->params['action'] = strtolower($this->params['action']);
if ($this->isConnected and $this->User->getKey('rank') == 5 and $this->params['controller'] != "maintenance" and $this->params['action'] != "logout" and $this->params['controller'] != "api")
$this->redirect(array('controller' => 'maintenance', 'action' => 'index/banned', 'plugin' => false, 'admin' => false));
else if ($this->params['controller'] != "user" && $this->params['controller'] != "maintenance" && $this->Configuration->getKey('maintenance') != '0' && !$this->Permissions->can('BYPASS_MAINTENANCE') && $LoginCondition)
$this->redirect(array('controller' => 'maintenance', 'action' => 'index', 'plugin' => false, 'admin' => false));
if ($this->isConnected and $this->User->getKey('rank') == 5 and $this->params['controller'] != "maintenance" and $this->params['action'] != "logout" and $this->params['controller'] != "api") {
$this->redirect(array(
'controller' => 'maintenance',
'action' => 'index/banned',
'plugin' => false,
'admin' => false
));
} else {
if ($this->params['controller'] != "user" && $this->params['controller'] != "maintenance" && $this->Configuration->getKey('maintenance') != '0' && !$this->Permissions->can('BYPASS_MAINTENANCE') && $LoginCondition) {
$this->redirect(array(
'controller' => 'maintenance',
'action' => 'index',
'plugin' => false,
'admin' => false
));
}
}

}

Expand Down Expand Up @@ -170,14 +183,9 @@ private function __initUser()
$this->loadModel('User');

if (!$this->User->isConnected() && ($cookie = $this->Cookie->read('remember_me')) && isset($cookie['pseudo']) && isset($cookie['password'])) {
$user = $this->User->find('first', array(
'conditions' => array(
'pseudo' => $cookie['pseudo'],
'password' => $cookie['password']
)
));
$user = $this->User->find('first', array('conditions' => array('pseudo' => $cookie['pseudo'])));

if (!empty($user))
if (!empty($user) && $user['User']['password'] == $cookie['password'])
$this->Session->write('user', $user['User']['id']);
}

Expand Down Expand Up @@ -370,12 +378,16 @@ function addToNav($menus, $nav, $index = 0)

// Add slider if !useless
$themeConfig = $this->Theme->getConfig(Configure::read('theme'));
if (isset($themeConfig->slider) && $themeConfig->slider)
$nav['GLOBAL__CUSTOMIZE']['menu'] = addToArrayAt($nav['GLOBAL__CUSTOMIZE']['menu'], count($nav['GLOBAL__CUSTOMIZE']['menu']), ['SLIDER__TITLE' => [
'icon' => 'far fa-image',
'permission' => 'MANAGE_SLIDER',
'route' => ['controller' => 'slider', 'action' => 'index', 'admin' => true, 'plugin' => false]
]]);
if (isset($themeConfig->slider) && $themeConfig->slider) {
$nav['GLOBAL__CUSTOMIZE']['menu'] = addToArrayAt($nav['GLOBAL__CUSTOMIZE']['menu'],
count($nav['GLOBAL__CUSTOMIZE']['menu']), [
'SLIDER__TITLE' => [
'icon' => 'far fa-image',
'permission' => 'MANAGE_SLIDER',
'route' => ['controller' => 'slider', 'action' => 'index', 'admin' => true, 'plugin' => false]
]
]);
}

// Handle plugins
$plugins = $this->EyPlugin->pluginsLoaded;
Expand Down Expand Up @@ -435,12 +447,15 @@ public function __initServerInfos()
if (!isset($server_infos['GET_MAX_PLAYERS']) || !isset($server_infos['GET_PLAYER_COUNT']) || $server_infos['GET_MAX_PLAYERS'] === 0)
return $this->set(['banner_server' => false, 'server_infos' => $server_infos]);

$this->set(['banner_server' => $this->Lang->get('SERVER__STATUS_MESSAGE', array(
'{MOTD}' => @$server_infos['getMOTD'],
'{VERSION}' => @$server_infos['getVersion'],
'{ONLINE}' => @$server_infos['GET_PLAYER_COUNT'],
'{ONLINE_LIMIT}' => @$server_infos['GET_MAX_PLAYERS']
)), 'server_infos' => $server_infos]);
$this->set([
'banner_server' => $this->Lang->get('SERVER__STATUS_MESSAGE', array(
'{MOTD}' => @$server_infos['getMOTD'],
'{VERSION}' => @$server_infos['getVersion'],
'{ONLINE}' => @$server_infos['GET_PLAYER_COUNT'],
'{ONLINE_LIMIT}' => @$server_infos['GET_MAX_PLAYERS']
)),
'server_infos' => $server_infos
]);

}

Expand Down
Loading

0 comments on commit f537925

Please sign in to comment.