aboutsummaryrefslogtreecommitdiff
path: root/controllers/admin.php
blob: 2b8e97ba3a78ac3743da826476e362107104b213 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
    }
}