CleanUp After Docker Try

This commit is contained in:
JonatanRek
2020-05-16 17:18:27 +02:00
parent 2f638d8091
commit 090b9f7a7b
123 changed files with 5265 additions and 0 deletions

36
library/ApiController.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
class ApiController {
protected $input;
protected $authenticated = false;
function __construct() {
$input = file_get_contents('php://input');
if(empty($input)){
$this->input = NULL;
}else{
$this->input = json_decode($input, true);
if(json_last_error() != JSON_ERROR_NONE){
throw new Exception("Invalid request payload", 400);
}
}
}
protected function requireAuth(){
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
// TODO: call appropriate class/method
$authManager = new AuthManager();
$this->authenticated = $authManager>validateToken($_SERVER['HTTP_AUTHORIZATION']);
if(!$this->authenticated){
throw new Exception("Authorization required", 401);
}
} else {
throw new Exception("Authorization required", 401);
}
}
protected function response($data = [], $httpCode = '200'){
http_response_code($httpCode);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
}