From 332d13a0c88f69af8a97b990edbe4209805fc117 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Fri, 20 Jan 2023 20:49:59 +0100 Subject: [PATCH] Add function is_admin() to Session --- Kernel/Session.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Kernel/Session.php b/Kernel/Session.php index cc70040..8712087 100644 --- a/Kernel/Session.php +++ b/Kernel/Session.php @@ -65,11 +65,17 @@ final class Session } } + public static function is_admin(){ + if (!self::is_login()) return false; + + $O_userModel = new UserModel(); + return $O_userModel->isUserAdmin($_SESSION["ID"]); + } + public static function admin_or_die(){ Session::login_or_die(); - $O_userModel = new UserModel(); - if (!$O_userModel->isUserAdmin($_SESSION["ID"])) { + if (!self::is_admin()) { header("Location: /"); die(); }