diff options
| author | Syndamia <kamen@syndamia.com> | 2025-02-02 15:52:58 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-02-02 15:52:58 +0200 |
| commit | e0fe3d0a5b6dd8bf4ba11eee10adfb6be3f5ab31 (patch) | |
| tree | e0562c4683f27c7700ceb16e6faa3a06dd3f50f8 /controllers/admin.php | |
| parent | 179ebaebc36b6dc470dacad5a9020e4d6bf9921a (diff) | |
| download | nowayforward_human-e0fe3d0a5b6dd8bf4ba11eee10adfb6be3f5ab31.tar nowayforward_human-e0fe3d0a5b6dd8bf4ba11eee10adfb6be3f5ab31.tar.gz nowayforward_human-e0fe3d0a5b6dd8bf4ba11eee10adfb6be3f5ab31.zip | |
feat: Implement admin panel with the ability to change role of users
Diffstat (limited to 'controllers/admin.php')
| -rw-r--r-- | controllers/admin.php | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ +<?php +namespace Controller; +use Database; +use Exception; + +function on_patch() { + global $TOKEN; + global $METHOD; + global $role_status; + $role_status = ""; + + $status = null; + switch ($METHOD['type']) { + case 'role': $status = 'role_status'; break; + default: throw new Exception('Invalid patch type ' . $METHOD['type']); + } + + $user = null; + try { + $user = Database\Cookie::fromDB($TOKEN); + } + catch(Exception $e) { + $$status = "Couldn't retrieve user!"; + return; + } + + switch ($METHOD['type']) { + case 'role': + try { + $to_update = Database\User::fromDB($METHOD['username']); + $to_update->update($to_update->Username, null, $METHOD['role']); + } + catch (Exception $e) { + $$status = "User doesn't exist!"; + return; + } + break; + } +} |
