fixed and improved authentication level methods
This commit is contained in:
parent
ab375e636e
commit
ef6d621374
@ -24,6 +24,11 @@ class AuthenticationManager implements CallbackListener {
|
||||
const AUTH_LEVEL_ADMIN = 2;
|
||||
const AUTH_LEVEL_SUPERADMIN = 3;
|
||||
const AUTH_LEVEL_MASTERADMIN = 4;
|
||||
const AUTH_NAME_PLAYER = 'Player';
|
||||
const AUTH_NAME_MODERATOR = 'Moderator';
|
||||
const AUTH_NAME_ADMIN = 'Admin';
|
||||
const AUTH_NAME_SUPERADMIN = 'SuperAdmin';
|
||||
const AUTH_NAME_MASTERADMIN = 'MasterAdmin';
|
||||
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
|
||||
|
||||
/*
|
||||
@ -96,8 +101,8 @@ class AuthenticationManager implements CallbackListener {
|
||||
return false;
|
||||
}
|
||||
$success = true;
|
||||
foreach($masterAdmins as $masterAdmin) {
|
||||
$login = (string)$masterAdmin;
|
||||
foreach ($masterAdmins as $masterAdmin) {
|
||||
$login = (string) $masterAdmin;
|
||||
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
||||
$adminStatement->execute();
|
||||
if ($adminStatement->error) {
|
||||
@ -113,25 +118,23 @@ class AuthenticationManager implements CallbackListener {
|
||||
* Get a List of all Admins
|
||||
*
|
||||
* @param $authLevel
|
||||
* @return array|null
|
||||
* @return array null
|
||||
*/
|
||||
public function getAdmins($authLevel = -1) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
if ($authLevel == -1) {
|
||||
if ($authLevel < 0) {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";";
|
||||
}
|
||||
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$admins = array();
|
||||
while($row = $result->fetch_object()) {
|
||||
while ($row = $result->fetch_object()) {
|
||||
array_push($admins, $row);
|
||||
}
|
||||
return $admins;
|
||||
@ -148,7 +151,7 @@ class AuthenticationManager implements CallbackListener {
|
||||
if (!$player || !is_numeric($authLevel)) {
|
||||
return false;
|
||||
}
|
||||
$authLevel = (int)$authLevel;
|
||||
$authLevel = (int) $authLevel;
|
||||
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) {
|
||||
return false;
|
||||
}
|
||||
@ -234,25 +237,20 @@ class AuthenticationManager implements CallbackListener {
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthLevelName($authLevelInt) {
|
||||
//FIXME somehow it fails here (look also AdminList.php)
|
||||
if ($authLevelInt instanceof Player) {
|
||||
$authLevelInt = $authLevelInt->authLevel;
|
||||
} else {
|
||||
$authLevelInt = (int) $authLevelInt;
|
||||
$authLevelInt = self::getAuthLevelInt($authLevelInt);
|
||||
if ($authLevelInt === self::AUTH_LEVEL_MASTERADMIN) {
|
||||
return self::AUTH_NAME_MASTERADMIN;
|
||||
}
|
||||
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
||||
return 'MasterAdmin';
|
||||
if ($authLevelInt === self::AUTH_LEVEL_SUPERADMIN) {
|
||||
return self::AUTH_NAME_SUPERADMIN;
|
||||
}
|
||||
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
|
||||
return 'SuperAdmin';
|
||||
if ($authLevelInt === self::AUTH_LEVEL_ADMIN) {
|
||||
return self::AUTH_NAME_ADMIN;
|
||||
}
|
||||
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
|
||||
return 'Admin';
|
||||
if ($authLevelInt === self::AUTH_LEVEL_MODERATOR) {
|
||||
return self::AUTH_NAME_MODERATOR;
|
||||
}
|
||||
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
|
||||
return 'Moderator';
|
||||
}
|
||||
return 'Player';
|
||||
return self::AUTH_NAME_PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,21 +260,17 @@ class AuthenticationManager implements CallbackListener {
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthLevelAbbreviation($authLevelInt) {
|
||||
if ($authLevelInt instanceof Player) {
|
||||
$authLevelInt = $authLevelInt->authLevel;
|
||||
} else {
|
||||
$authLevelInt = (int) $authLevelInt;
|
||||
}
|
||||
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
|
||||
$authLevelInt = self::getAuthLevelInt($authLevelInt);
|
||||
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 '';
|
||||
@ -290,18 +284,31 @@ class AuthenticationManager implements CallbackListener {
|
||||
*/
|
||||
public static function getAuthLevel($authLevelName) {
|
||||
$authLevelName = strtolower($authLevelName);
|
||||
if ($authLevelName == 'MasterAdmin') {
|
||||
if ($authLevelName === self::AUTH_NAME_MASTERADMIN) {
|
||||
return self::AUTH_LEVEL_MASTERADMIN;
|
||||
}
|
||||
if ($authLevelName == 'SuperAdmin') {
|
||||
if ($authLevelName === self::AUTH_NAME_SUPERADMIN) {
|
||||
return self::AUTH_LEVEL_SUPERADMIN;
|
||||
}
|
||||
if ($authLevelName == 'Admin') {
|
||||
if ($authLevelName === self::AUTH_NAME_ADMIN) {
|
||||
return self::AUTH_LEVEL_ADMIN;
|
||||
}
|
||||
if ($authLevelName == 'Moderator') {
|
||||
if ($authLevelName === self::AUTH_NAME_MODERATOR) {
|
||||
return self::AUTH_LEVEL_MODERATOR;
|
||||
}
|
||||
return self::AUTH_LEVEL_PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Authentication Level Int from the given Param
|
||||
*
|
||||
* @param mixed $authLevelParam
|
||||
* @return int
|
||||
*/
|
||||
public static function getAuthLevelInt($authLevelParam) {
|
||||
if (is_object($authLevelParam) && property_exists($authLevelParam, 'authLevel')) {
|
||||
return (int) $authLevelParam->authLevel;
|
||||
}
|
||||
return (int) $authLevelParam;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user