-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
58 lines (50 loc) · 1.17 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
53
54
55
56
57
58
<?php
/**
* RestServer main controller
*
* @author Pierre HUBERT
*/
/**
* Page initiator
*/
require(__DIR__."/system/init.inc.php");
/**
* RestServer inclusion
*/
require(SYSTEM_PATH."RestServer/RestServer.php");
/**
* Security check
*/
//If the user is logged in, everything is OK, else we must check tokens
if(!$amss->user->userLoggedIn()){
//We check tokens (if there is)
if(!isset($_POST['token1']) OR !isset($_POST['token2'])){
Rest_fatal_Error(401, "Please login!");
}
if(!$amss->user->checkTokens($_POST['token1'], $_POST['token2'])){
Rest_fatal_Error(401, "Access denied!");
}
}
/**
* Create RestServer object
*/
$siteState = $amss->config->get("site_mode");
$server = new \Jacwright\RestServer\RestServer($siteState);
/**
* Auto-load controllers
*/
foreach(glob(SYSTEM_PATH."RestServerControllers/*.php") as $file_name){
//Determine classname
$classname = str_replace(
array(".php", "Controllers/"),
"",
strstr($file_name, "Controllers")
);
//Require class and include it
require($file_name);
$server->addClass($classname);
}
/**
* Handle request
*/
$server->handle();