From a8bba121075acec877328a09420b7a0a7b860f56 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:29:43 +0100 Subject: [PATCH] use a separate UserSessionModel in Session --- Models/UserModel.php | 26 +----------------------- Modules/Session/Session.php | 8 ++++---- Modules/Session/UserSessionModel.php | 30 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 Modules/Session/UserSessionModel.php diff --git a/Models/UserModel.php b/Models/UserModel.php index 55c9f10..a7ef0f5 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -1,6 +1,6 @@ prepare("SELECT DISABLED FROM USER WHERE ID=:id"); - $stmt->bindParam("id", $I_id); - $stmt->execute(); - - $row = $stmt->fetch(); - if ($row === false) return false; - return $row["DISABLED"] !== 1; - } - - public function isUserAdmin($I_id) - { - $O_model = Model::get(); - $stmt = $O_model->prepare("SELECT ADMIN FROM USER WHERE ID=:id"); - $stmt->bindParam("id", $I_id); - $stmt->execute(); - - $row = $stmt->fetch(); - if ($row === false) return false; - return $row["ADMIN"] === 1; - } public function updateEmailByID($I_id, $S_newEmail){ $O_model = Model::get(); diff --git a/Modules/Session/Session.php b/Modules/Session/Session.php index 8712087..828e00b 100644 --- a/Modules/Session/Session.php +++ b/Modules/Session/Session.php @@ -47,8 +47,8 @@ final class Session } // ensure account has not been deleted/disabled in the meantime - $O_userModel = new UserModel(); - $B_userActive = $O_userModel->isUserActive($_SESSION["ID"]); + $O_userSessionModel = new UserSessionModel(); + $B_userActive = $O_userSessionModel->isUserActive($_SESSION["ID"]); return $B_userActive; } @@ -68,8 +68,8 @@ final class Session public static function is_admin(){ if (!self::is_login()) return false; - $O_userModel = new UserModel(); - return $O_userModel->isUserAdmin($_SESSION["ID"]); + $O_userSessionModel = new UserSessionModel(); + return $O_userSessionModel->isUserAdmin($_SESSION["ID"]); } public static function admin_or_die(){ diff --git a/Modules/Session/UserSessionModel.php b/Modules/Session/UserSessionModel.php new file mode 100644 index 0000000..2f666f5 --- /dev/null +++ b/Modules/Session/UserSessionModel.php @@ -0,0 +1,30 @@ +prepare("SELECT DISABLED FROM USER WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return false; + return $row["DISABLED"] !== 1; + } + + public function isUserAdmin($I_id) + { + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT ADMIN FROM USER WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return false; + return $row["ADMIN"] === 1; + } + +}