From e0fe3d0a5b6dd8bf4ba11eee10adfb6be3f5ab31 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 2 Feb 2025 15:52:58 +0200 Subject: feat: Implement admin panel with the ability to change role of users --- controllers/admin.php | 39 +++++++++++++++++++++++++++++++++++++++ models/user.php | 6 ++++-- views/admin/index.php | 34 ++++++++++++++++++++++++++++++++++ views/admin/meta.php | 4 ++++ views/global/router.php | 1 + views/user/index.php | 5 +++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 controllers/admin.php create mode 100644 views/admin/index.php create mode 100644 views/admin/meta.php diff --git a/controllers/admin.php b/controllers/admin.php new file mode 100644 index 0000000..2b8e97b --- /dev/null +++ b/controllers/admin.php @@ -0,0 +1,39 @@ +update($to_update->Username, null, $METHOD['role']); + } + catch (Exception $e) { + $$status = "User doesn't exist!"; + return; + } + break; + } +} diff --git a/models/user.php b/models/user.php index 71cf07d..6ff2f70 100644 --- a/models/user.php +++ b/models/user.php @@ -60,16 +60,18 @@ class User extends Table { private static $AnonUID = 1; - function update(string $Username, string $Password = null) { + function update(string $Username = null, string $Password = null, string $Role = null) { // Applicable to Anon user if ($this->Password === '') { throw new Exception('Not modifying system account!'); } + $Username = $Username ?? $this->Username; $Password = ($Password === null) ? $this->Password : password_hash($Password, PASSWORD_BCRYPT); + $Role = $Role ?? $this->Role; Table::_update( 'Users', - "Username = \"$Username\", Password = \"$Password\"", + "Username = \"$Username\", Password = \"$Password\", Role = \"$Role\"", "UID = \"$this->UID\"" ); } diff --git a/views/admin/index.php b/views/admin/index.php new file mode 100644 index 0000000..69495d6 --- /dev/null +++ b/views/admin/index.php @@ -0,0 +1,34 @@ + + +Role === 'Admin'): ?> +

Change role

+ +
+ + + +

+ Error: +

+ +

+ Success! +

+ + + + + + + +
+ + +

Permission denied, you're not an admin!

+ + diff --git a/views/admin/meta.php b/views/admin/meta.php new file mode 100644 index 0000000..0a151ba --- /dev/null +++ b/views/admin/meta.php @@ -0,0 +1,4 @@ + + Role === 'Admin'): ?> +
+ +
+