Base API, and more solid key and check
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Base;
|
||||
|
||||
$app->group('/api', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'api']);
|
||||
if (file_exists($folder)) {
|
||||
@ -10,4 +12,5 @@ $app->group('/api', function($app) {
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
$app->get('[/]', Base::class);
|
||||
})->add($app->getContainer()->get(Incoviba\Middleware\API::class));
|
||||
|
@ -2,6 +2,13 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function cleanNoCache() {
|
||||
const url = new URL(window.location.href)
|
||||
if (url.searchParams.has('nocache')) {
|
||||
url.searchParams.delete('nocache')
|
||||
window.location.href = url.href
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
@ -10,7 +17,11 @@
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
||||
@if (!$login->isIn())
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
||||
@else
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}{{$login->getSeparator()}}{{$login->getToken()}}'
|
||||
@endif
|
||||
}
|
||||
return fetch(url, options).then(response => {
|
||||
if (response.ok) {
|
||||
@ -36,6 +47,7 @@
|
||||
date: 'DD-MM-YYYY'
|
||||
},
|
||||
}
|
||||
cleanNoCache()
|
||||
</script>
|
||||
|
||||
@stack('page_scripts')
|
||||
|
Reference in New Issue
Block a user