-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
executable file
·52 lines (38 loc) · 1.18 KB
/
api.php
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
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once 'definitions.php';
require_once CLASS_PATH . 'ApiError.php';
// Since the JSON is not formatted as a query string,
// we need to get the raw POST data directly from the input stream.
$post = file_get_contents('php://input');
if ($post !== false) {
$json = json_decode($post);
if (!is_null($json)) {
switch ($_GET['action']) {
case 'login':
require_once CLASS_PATH . 'Auth.php';
if(!isset($json->username) || !isset($json->password)) {
$response = ApiError::MISSING_PARAM;
break;
}
$response = Auth::checkLogin($json->username, $json->password);
break;
case 'register':
require_once CLASS_PATH . 'Auth.php';
if(!isset($json->username) || !isset($json->password)) {
$response = ApiError::MISSING_PARAM;
break;
}
$response = Auth::register($json->username, $json->password);
break;
default:
$response = ApiError::INVALID_ACTION;
}
} else {
$response = ApiError::INVALID_JSON;
}
} else {
$response = ApiError::MISSING_REQUEST;
}
@header('Content-Type: text/json; charset=UTF-8');
echo json_encode($response);
?>