2021-03-27 21:59:44 +01:00
|
|
|
<?php
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
|
|
|
//include "brain/data/Auth.inc.php";
|
|
|
|
|
|
|
|
class APIControl
|
|
|
|
{
|
|
|
|
public static function start(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
2021-03-29 00:22:00 +02:00
|
|
|
): ResponseInterface {
|
2021-03-27 21:59:44 +01:00
|
|
|
$contentType = $request->getHeaderLine("Content-Type");
|
|
|
|
switch ($contentType) {
|
|
|
|
case "application/json":
|
|
|
|
$body = json_decode(file_get_contents("php://input"), true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//there's only one verion of the api for now
|
|
|
|
switch (isset($args["third"]) ? $args["third"] : "none") {
|
|
|
|
case "login":
|
2021-03-29 00:22:00 +02:00
|
|
|
$result = Auth::login($body);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "logout":
|
|
|
|
$result = Auth::logout($body);
|
2021-03-27 21:59:44 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$result = [
|
|
|
|
"message" => "Oh, nothing to do. That's unfortunate",
|
|
|
|
"type" => "TASK_NONE",
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response->getBody()->write(json_encode($result));
|
2021-03-29 00:22:00 +02:00
|
|
|
|
2021-03-27 21:59:44 +01:00
|
|
|
return $response->withHeader("Content-Type", "application/json");
|
|
|
|
}
|
|
|
|
}
|