From fae13defa5d036e4f98a8f50dca3f140d9c35ec5 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 22 Feb 2019 10:05:50 +0100 Subject: [PATCH] Added super user flag. --- .../2019_02_22_084055_super_user_flag.php | 20 +++++++++++++++++++ public/manage/users.php | 19 +++++++++--------- public/profile.php | 2 +- src/Users/user.php | 17 ++++++++++++++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 database/2019_02_22_084055_super_user_flag.php diff --git a/database/2019_02_22_084055_super_user_flag.php b/database/2019_02_22_084055_super_user_flag.php new file mode 100644 index 00000000..5e75a988 --- /dev/null +++ b/database/2019_02_22_084055_super_user_flag.php @@ -0,0 +1,20 @@ +exec(" + ALTER TABLE `msz_users` + ADD COLUMN `user_super` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER `last_ip`; + "); +} + +function migrate_down(PDO $conn): void +{ + $conn->exec(" + ALTER TABLE `msz_users` + DROP COLUMN `user_super`; + "); +} diff --git a/public/manage/users.php b/public/manage/users.php index 38cff514..25721a44 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -1,7 +1,8 @@ execute() ? $getAddress->fetchColumn() : ''; } +function user_check_super(int $userId): bool +{ + static $superUsers = []; + + if (!isset($superUsers[$userId])) { + $checkSuperUser = db_prepare(" + SELECT `user_super` + FROM `msz_users` + WHERE `user_id` = :user_id + "); + $checkSuperUser->bindValue('user_id', $userId); + $superUsers[$userId] = (bool)($checkSuperUser->execute() ? $checkSuperUser->fetchColumn() : false); + } + + return $superUsers[$userId]; +} + function user_check_authority(int $userId, int $subjectId, bool $canManageSelf = true): bool { if ($canManageSelf && $userId === $subjectId) {