aboutsummaryrefslogtreecommitdiff
path: root/views/profile/authenticate.php
blob: afe1ca78e1ddb7302074df497c72f0fae6ade20d (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
<?php

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Allow: POST');
    http_response_code(405);
    header('Content-Type: text/plain');
    echo $_SERVER['REQUEST_METHOD'] . " request not allowed!";
    exit;
}

try {
    $headers = apache_request_headers();
    $user = Database\Cookie::fromDB($headers["Authorization"]);

    http_response_code(200);
    header('Content-Type: text/plain');
    echo $user->Username;
}
catch(Exception $e) {
    http_response_code(401);
    header('Content-Type: text/plain');
    echo 'Bad token!';
}

exit;