-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
88 lines (75 loc) · 2.85 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
require 'vendor/autoload.php';
$lifetime = 0;
session_set_cookie_params($lifetime);
session_start();
$app = new \Slim\Slim();
$app->get('/login/:uniqueurl', function($uniqueUrl) use($app) {
$loginController = new \Main\Controller\LoginController($uniqueUrl);
$response = $loginController->attemptLogin();
if(isset($response['userData'])) {
$_SESSION['userData'] = $response['userData'];
}
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->post('/updateUsername/', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$response = null;
if(property_exists($body,'user_id') && property_exists($body,'new_username')) {
$userId = new \MongoId($body->user_id);
$newUsername = $body->new_username;
$userInformationController = new Main\Controller\UserInformationController();
$response = $userInformationController->updateUsername($userId, $newUsername);
}
else {
$response = json_encode(array('status' => '400', 'message' => "Missing input data."));
}
$app->response()->header("Content-Type", "application/json");
echo($response);
});
$app->post('/userVote', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$votingController = new \Main\Controller\VotingController();
$response = $votingController->placeVote($body);
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->post('/leaveComment', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$messageController = new \Main\Controller\MessageController();
$response = $messageController->leaveMessage($body);
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->post('/leaveReply', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$messageController = new \Main\Controller\MessageController();
$response = $messageController->leaveResponse($body);
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->post('/refreshMessages', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$messageController = new \Main\Controller\MessageController();
$response = $messageController->getMessages($body);
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->post('/refreshOptionMessageKeys', function() use($app) {
$body = $app->request()->getBody();
$body = json_decode($body);
$messageController = new \Main\Controller\MessageController();
$response = $messageController->getMessageIds($body);
$app->response()->header("Content-Type", "application/json");
echo(json_encode($response));
});
$app->run();
?>