2021-03-27 21:59:44 +01:00
|
|
|
<?php
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
2021-04-17 05:50:03 +02:00
|
|
|
include "../brain/api/v1/AuthAPI.inc.php";
|
2021-04-14 00:20:57 +02:00
|
|
|
include "../brain/api/v1/ImagesAPI.inc.php";
|
2021-04-14 21:01:49 +02:00
|
|
|
include "../brain/api/v1/PagesAPI.inc.php";
|
2021-04-16 07:19:59 +02:00
|
|
|
include "../brain/api/v1/SettingsAPI.inc.php";
|
2021-04-24 05:54:56 +02:00
|
|
|
include "../brain/api/v1/InitAPI.inc.php";
|
2021-03-27 21:59:44 +01:00
|
|
|
|
|
|
|
class APIControl
|
|
|
|
{
|
2021-04-01 21:54:03 +02:00
|
|
|
public static function get(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
|
|
|
): ResponseInterface {
|
|
|
|
switch (isset($args["third"]) ? $args["third"] : "none") {
|
|
|
|
case "status":
|
2021-04-17 05:50:03 +02:00
|
|
|
$result = AuthAPI::status();
|
2021-04-01 21:54:03 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$response->getBody()->write(json_encode($result));
|
|
|
|
return $response->withHeader("Content-Type", "application/json");
|
|
|
|
}
|
|
|
|
public static function post(
|
2021-03-27 21:59:44 +01:00
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
2021-03-29 00:22:00 +02:00
|
|
|
): ResponseInterface {
|
2021-04-10 22:19:05 +02:00
|
|
|
$contentType = $request->getHeader("Content-Type");
|
|
|
|
switch ($contentType[0]) {
|
2021-03-27 21:59:44 +01:00
|
|
|
case "application/json":
|
|
|
|
$body = json_decode(file_get_contents("php://input"), true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (isset($args["third"]) ? $args["third"] : "none") {
|
2021-04-24 05:54:56 +02:00
|
|
|
case "init":
|
|
|
|
$result = InitApi::handleInitTasks($args["third"], $body);
|
|
|
|
break;
|
2021-03-27 21:59:44 +01:00
|
|
|
case "login":
|
2021-04-17 05:50:03 +02:00
|
|
|
$result = AuthAPI::login($body);
|
2021-03-29 00:22:00 +02:00
|
|
|
break;
|
|
|
|
case "logout":
|
2021-04-17 05:50:03 +02:00
|
|
|
$result = AuthAPI::logout($body);
|
2021-04-14 00:20:57 +02:00
|
|
|
break;
|
|
|
|
case "page":
|
|
|
|
$token = $request->getHeader("fipamo-access-token");
|
2021-04-14 21:01:49 +02:00
|
|
|
//Verify token for admin tasks
|
2021-04-14 00:20:57 +02:00
|
|
|
if (Session::verifyToken($token[0])) {
|
2021-04-14 21:01:49 +02:00
|
|
|
$result = PagesAPI::handlePageTask($request, $args);
|
2021-04-14 00:20:57 +02:00
|
|
|
} else {
|
|
|
|
$result = [
|
|
|
|
"message" => "API access denied, homie",
|
|
|
|
"type" => "API_ERROR",
|
|
|
|
];
|
|
|
|
}
|
2021-03-27 21:59:44 +01:00
|
|
|
break;
|
2021-04-16 07:19:59 +02:00
|
|
|
case "settings":
|
|
|
|
$token = $request->getHeader("fipamo-access-token");
|
|
|
|
if (Session::verifyToken($token[0])) {
|
2021-04-17 01:15:47 +02:00
|
|
|
$result = SettingsAPI::handleSettingsTask($request, $args, $body);
|
2021-04-16 07:19:59 +02:00
|
|
|
} else {
|
|
|
|
$result = [
|
|
|
|
"message" => "API access denied, homie",
|
|
|
|
"type" => "API_ERROR",
|
|
|
|
];
|
|
|
|
}
|
|
|
|
break;
|
2021-03-27 21:59:44 +01:00
|
|
|
default:
|
|
|
|
$result = [
|
|
|
|
"message" => "Oh, nothing to do. That's unfortunate",
|
|
|
|
"type" => "TASK_NONE",
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response->getBody()->write(json_encode($result));
|
|
|
|
return $response->withHeader("Content-Type", "application/json");
|
|
|
|
}
|
|
|
|
}
|