Newer
Older
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
40
<?php
${basename(__FILE__, '.php')} = function(){
if($this->isAuthenticated())
{
$data = [
'error' => 'Already logged in'
];
$data = $this->json($data);
$this->response($data, 400);
}
if($this->get_request_method() == "POST" and isset($this->_request['username']) and isset($this->_request['password'])){
$username = $this->_request['username'];
$password = $this->_request['password'];
try {
$auth = new Auth($username, $password);
$data = [
"message" => "Login success",
"token" => $auth->getAuthTokens()
];
$data = $this->json($data);
$this->response($data, 200);
} catch(Exception $e){
$data = [
"error" => $e->getMessage()
];
$data = $this->json($data);
$this->response($data, 406);
}
} else {
$data = [
"error" => "Bad request"
];
$data = $this->json($data);
$this->response($data, 400);
}
};
?>