diff --git a/Kernel/Constants.php b/Kernel/Constants.php index ac075eb..f42583d 100644 --- a/Kernel/Constants.php +++ b/Kernel/Constants.php @@ -14,6 +14,8 @@ final class Constants const CONTROLLERS_DIR = '/Controllers/'; + const MODULES_DIR = '/Modules/'; + public static function rootDir() { return realpath(__DIR__ . '/../'); @@ -39,4 +41,8 @@ final class Constants return self::rootDir() . self::CONTROLLERS_DIR; } + public static function modulesDir() { + return self::rootDir() . self::MODULES_DIR; + } + } 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/AutoLoad.php b/Modules/AutoLoad.php new file mode 100644 index 0000000..9645721 --- /dev/null +++ b/Modules/AutoLoad.php @@ -0,0 +1,28 @@ +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; + } + +} diff --git a/index.php b/index.php index 2d13d2d..27c2fe2 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ require 'vendor/autoload.php'; require 'Kernel/AutoLoad.php'; + require 'Modules/AutoLoad.php'; $dotenv = Dotenv\Dotenv::createImmutable(Constants::rootDir()); $dotenv->load();