fixed authentication manager
This commit is contained in:
parent
f9041748f6
commit
161ef44508
@ -5,6 +5,8 @@ namespace ManiaControl\Admin;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
|
||||||
require_once __DIR__ . '/AuthCommands.php';
|
require_once __DIR__ . '/AuthCommands.php';
|
||||||
|
|
||||||
@ -13,7 +15,7 @@ require_once __DIR__ . '/AuthCommands.php';
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class AuthenticationManager {
|
class AuthenticationManager implements CallbackListener {
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
@ -35,20 +37,23 @@ class AuthenticationManager {
|
|||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct authentication manager
|
* Construct a new Authentication Manager
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
* @param \ManiaControl\ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->updateMasterAdmins();
|
|
||||||
|
|
||||||
$this->authCommands = new AuthCommands($maniaControl);
|
$this->authCommands = new AuthCommands($maniaControl);
|
||||||
|
|
||||||
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleOnInit(array $callback) {
|
||||||
|
$this->updateMasterAdmins();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set MasterAdmins
|
* Update MasterAdmins based on config
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -60,7 +65,7 @@ class AuthenticationManager {
|
|||||||
SET `authLevel` = ?
|
SET `authLevel` = ?
|
||||||
WHERE `authLevel` = ?;";
|
WHERE `authLevel` = ?;";
|
||||||
$adminStatement = $mysqli->prepare($adminQuery);
|
$adminStatement = $mysqli->prepare($adminQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -68,7 +73,7 @@ class AuthenticationManager {
|
|||||||
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
|
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
|
||||||
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
|
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
|
||||||
$adminStatement->execute();
|
$adminStatement->execute();
|
||||||
if($adminStatement->error) {
|
if ($adminStatement->error) {
|
||||||
trigger_error($adminStatement->error);
|
trigger_error($adminStatement->error);
|
||||||
}
|
}
|
||||||
$adminStatement->close();
|
$adminStatement->close();
|
||||||
@ -83,16 +88,16 @@ class AuthenticationManager {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`authLevel` = VALUES(`authLevel`);";
|
`authLevel` = VALUES(`authLevel`);";
|
||||||
$adminStatement = $mysqli->prepare($adminQuery);
|
$adminStatement = $mysqli->prepare($adminQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
||||||
$success = true;
|
$success = true;
|
||||||
foreach($masterAdmins as $masterAdmin) {
|
foreach ($masterAdmins as $masterAdmin) {
|
||||||
$login = (string)$masterAdmin;
|
$login = (string) $masterAdmin;
|
||||||
$adminStatement->execute();
|
$adminStatement->execute();
|
||||||
if($adminStatement->error) {
|
if ($adminStatement->error) {
|
||||||
trigger_error($adminStatement->error);
|
trigger_error($adminStatement->error);
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
@ -109,13 +114,9 @@ class AuthenticationManager {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function grantAuthLevel(Player &$player, $authLevel) {
|
public function grantAuthLevel(Player &$player, $authLevel) {
|
||||||
if(!$player || !is_numeric($authLevel)) {
|
if (!$player || !is_numeric($authLevel)) return false;
|
||||||
return false;
|
$authLevel = (int) $authLevel;
|
||||||
}
|
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) return false;
|
||||||
$authLevel = (int)$authLevel;
|
|
||||||
if($authLevel >= self::AUTH_LEVEL_MASTERADMIN) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
||||||
@ -126,13 +127,13 @@ class AuthenticationManager {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`authLevel` = VALUES(`authLevel`);";
|
`authLevel` = VALUES(`authLevel`);";
|
||||||
$authStatement = $mysqli->prepare($authQuery);
|
$authStatement = $mysqli->prepare($authQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$authStatement->bind_param('si', $player->login, $authLevel);
|
$authStatement->bind_param('si', $player->login, $authLevel);
|
||||||
$authStatement->execute();
|
$authStatement->execute();
|
||||||
if($authStatement->error) {
|
if ($authStatement->error) {
|
||||||
trigger_error($authStatement->error);
|
trigger_error($authStatement->error);
|
||||||
$authStatement->close();
|
$authStatement->close();
|
||||||
return false;
|
return false;
|
||||||
@ -152,9 +153,7 @@ class AuthenticationManager {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function sendNotAllowed(Player $player) {
|
public function sendNotAllowed(Player $player) {
|
||||||
if(!$player) {
|
if (!$player) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login);
|
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +190,6 @@ class AuthenticationManager {
|
|||||||
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
|
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Name of the Authentication Level from Level Int
|
* Get Name of the Authentication Level from Level Int
|
||||||
*
|
*
|
||||||
@ -199,16 +197,16 @@ class AuthenticationManager {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getAuthLevelName($authLevelInt) {
|
public static function getAuthLevelName($authLevelInt) {
|
||||||
if($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
||||||
return 'MasterAdmin';
|
return 'MasterAdmin';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
|
||||||
return 'SuperAdmin';
|
return 'SuperAdmin';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_ADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
|
||||||
return 'Admin';
|
return 'Admin';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
|
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
|
||||||
return 'Moderator';
|
return 'Moderator';
|
||||||
}
|
}
|
||||||
return 'Player';
|
return 'Player';
|
||||||
@ -221,16 +219,16 @@ class AuthenticationManager {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getAuthLevelAbbreviation($authLevelInt) {
|
public static function getAuthLevelAbbreviation($authLevelInt) {
|
||||||
if($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
||||||
return 'MA';
|
return 'MA';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
|
||||||
return 'SA';
|
return 'SA';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_ADMIN) {
|
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
|
||||||
return 'AD';
|
return 'AD';
|
||||||
}
|
}
|
||||||
if($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
|
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
|
||||||
return 'MOD';
|
return 'MOD';
|
||||||
}
|
}
|
||||||
return 'PL';
|
return 'PL';
|
||||||
@ -244,16 +242,16 @@ class AuthenticationManager {
|
|||||||
*/
|
*/
|
||||||
public static function getAuthLevel($authLevelName) {
|
public static function getAuthLevel($authLevelName) {
|
||||||
$authLevelName = strtolower($authLevelName);
|
$authLevelName = strtolower($authLevelName);
|
||||||
if($authLevelName == 'MasterAdmin') {
|
if ($authLevelName == 'MasterAdmin') {
|
||||||
return self::AUTH_LEVEL_MASTERADMIN;
|
return self::AUTH_LEVEL_MASTERADMIN;
|
||||||
}
|
}
|
||||||
if($authLevelName == 'SuperAdmin') {
|
if ($authLevelName == 'SuperAdmin') {
|
||||||
return self::AUTH_LEVEL_SUPERADMIN;
|
return self::AUTH_LEVEL_SUPERADMIN;
|
||||||
}
|
}
|
||||||
if($authLevelName == 'Admin') {
|
if ($authLevelName == 'Admin') {
|
||||||
return self::AUTH_LEVEL_ADMIN;
|
return self::AUTH_LEVEL_ADMIN;
|
||||||
}
|
}
|
||||||
if($authLevelName == 'Moderator') {
|
if ($authLevelName == 'Moderator') {
|
||||||
return self::AUTH_LEVEL_MODERATOR;
|
return self::AUTH_LEVEL_MODERATOR;
|
||||||
}
|
}
|
||||||
return self::AUTH_LEVEL_PLAYER;
|
return self::AUTH_LEVEL_PLAYER;
|
||||||
|
Loading…
Reference in New Issue
Block a user