diff options
| -rw-r--r-- | lib/accounts.php | 13 | ||||
| -rw-r--r-- | system/config.php | 4 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/accounts.php b/lib/accounts.php index 36f11af..a7a230e 100644 --- a/lib/accounts.php +++ b/lib/accounts.php @@ -49,8 +49,17 @@ function authorize_user(bool $required = false): bool $_SESSION["user_role"] = null; - if ($role_row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $_SESSION["user_role"] = $role_row; + if ($role = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($role["permission_admin"]) { + foreach ($role as $k => &$v) { + if (str_starts_with($k, 'permission_')) { + $v = 1; + } + } + unset($v); + } + + $_SESSION["user_role"] = $role; } $stmt = $db->prepare("SELECT es.*, aes.is_default FROM emote_sets es diff --git a/system/config.php b/system/config.php index 8e1879d..e03e95b 100644 --- a/system/config.php +++ b/system/config.php @@ -4,8 +4,8 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/partials.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php"; -if (file_exists(CFG_PATH) && !authorize_user(true) && !isset($_SESSION['user_role']['permission_admin'])) { - generate_alert('/', 'Unauthorized', 401); +if (file_exists(CFG_PATH) && (!authorize_user(true) || !isset($_SESSION['user_role']) || !$_SESSION['user_role']['permission_admin'])) { + generate_alert('/404.php', 'Unauthorized', 401); exit(); } |
