diff options
Diffstat (limited to 'controllers/session.php')
| -rw-r--r-- | controllers/session.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/controllers/session.php b/controllers/session.php new file mode 100644 index 0000000..179afe6 --- /dev/null +++ b/controllers/session.php @@ -0,0 +1,31 @@ +<?php +namespace Controller; +use Database; +use Exception; + +function on_post() { + global $user_status; + global $token; + $user_status = ""; + + try { + $user = Database\User::fromDB($_POST["username"]); + if (password_verify($_POST["password"], $user->Password)) { + $token = Database\Cookie::create($user->UID); + } + else { + $user_status = "Incorrect password!"; + } + } + catch(Exception $e) { + $user_status = "User \"" . $_POST["username"] . "\" doesn't exist!"; + } +} + +function on_delete() { + global $TOKEN; + try { + Database\Cookie::delete($TOKEN); + } + catch(Exception $e) {} +} |
