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