Updated calls for user session

Users token session must be set for calls to work
This commit is contained in:
cp6 2021-03-17 11:33:54 +11:00
parent 5fafca6dd4
commit c435d43137

View File

@ -2,9 +2,11 @@
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
require_once('class.php');
$idle = new idlers();
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$auth = new auth();
$auth->sessionStartIfNone();
if (isset($_SESSION['token'])) {
$idle = new idlers();
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['type'])) {
if ($_GET['type'] == 'server') {
echo $idle->serverData($_GET['id']);
@ -52,7 +54,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
echo $idle->compareTable($_GET['server1'], $_GET['server2']);
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['order_form'])) {
header('Content-Type: text/html; charset=utf-8');
echo $idle->orderTable($_POST['order_by']);//Returns order table
@ -97,4 +99,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
header('Location:index.php');
die();
}
}
} else {
header('HTTP/1.1 401 Unauthorized');
echo json_encode(array(
'code' => 401,
'message' => 'Unauthorized'));
exit;
}