diff options
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/user.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/controllers/user.php b/controllers/user.php index d79b294..ac906a0 100644 --- a/controllers/user.php +++ b/controllers/user.php @@ -22,6 +22,43 @@ function on_post() { } } +function on_patch() { + global $TOKEN; + global $METHOD; + global $username_status; + global $password_status; + $username_status = ""; + $password_status = ""; + + $status = null; + switch ($METHOD['type']) { + case 'username': $status = 'username_status'; break; + case 'password': $status = 'password_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 'username': + $user->update($METHOD['username']); + header('Location: /user/' . $METHOD['username']); + break; + case 'password': + $user->update($user->Username, $METHOD['password']); + header('Location: /user/' . $user->Username); + break; + } + exit(); +} + function on_delete() { global $TOKEN; global $METHOD; |
