-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
61 lines (47 loc) · 1.45 KB
/
index.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
53
54
55
56
57
58
59
60
61
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
include 'AutoLoader.php';
$app = new \Slim\Slim(array('debug' => true));
$app->get('/status/', function () use ($app){
header('Access-Control-Allow-Origin: *');
$res = $app->response();
try{
$adapter = new StatusAdapter();
$status = $adapter->IsSpaceOpen();
$responseData = array(
"openStatus" => $status['status'],
"updated" => $status['updated'],
);
$res->header('Content-Type', 'application/json');
echo json_encode($responseData);
} catch( Exception $e ){
$res->status(500);
// $res->header('X-Status-Reason', $e->getMessage());
}
});
$app->post('/status/', function() use ($app){
try{
$json = $app->request()->getBody();
$reqData = json_decode($json);
if( $reqData == null )
throw new Exception("Missing json body");
if( !isset($reqData->token) )
throw new Exception("Missing token");
if( !isset($reqData->openStatus) )
throw new Exception("Missing status parameter");
$tokenVerifier = new TokenVerifier();
if( !$tokenVerifier->IsTokenValid($reqData->token) ){
$app->response()->status(403);
return;
}
$adapter = new StatusAdapter();
$adapter->SetIsSpaceOpen($reqData->openStatus);
$app->response()->status(201);
} catch (Exception $e) {
$app->response()->status(400);
// $app->response()->header('X-Status-Reason', $e->getMessage());
}
});
$app->run();
?>