aboutsummaryrefslogtreecommitdiff
path: root/controllers/session.php
blob: e02cc79d43bfc2a566dacb66951dd9b077a09f64 (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
<?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 {
        $token = Database\Cookie::fromDBtoken($TOKEN);
        $token->delete();
    }
    catch(Exception $e) {}
}