Nicer Json

This commit is contained in:
JonatanRek 2020-03-13 16:28:50 +01:00
parent ca2cb2dbd2
commit e14a0edb3c
1 changed files with 6 additions and 6 deletions

12
api.php
View File

@ -64,7 +64,7 @@ if (DEBUGMOD != 1) {
echo json_encode(array( echo json_encode(array(
'state' => 'unsuccess', 'state' => 'unsuccess',
'errorMSG' => "Using API from your IP insnt alowed!", 'errorMSG' => "Using API from your IP insnt alowed!",
)); ), JSON_PRETTY_PRINT);
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
$logManager->write("[API] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordType::WARNING); $logManager->write("[API] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordType::WARNING);
exit(); exit();
@ -107,7 +107,7 @@ if ($token == null || $token == "") {
echo json_encode(array( echo json_encode(array(
'state' => 'unsuccess', 'state' => 'unsuccess',
'errorMSG' => "Missing Value Token in JSON payload", 'errorMSG' => "Missing Value Token in JSON payload",
)); ), JSON_PRETTY_PRINT);
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
die(); die();
} }
@ -147,7 +147,7 @@ if (!DeviceManager::registeret($token)) {
echo json_encode(array( echo json_encode(array(
'state' => 'unsuccess', 'state' => 'unsuccess',
'errorMSG' => "Device not registeret", 'errorMSG' => "Device not registeret",
)); ), JSON_PRETTY_PRINT);
$logManager->write("[API] Registering Device", LogRecordType::INFO); $logManager->write("[API] Registering Device", LogRecordType::INFO);
exit(); exit();
} }
@ -157,7 +157,7 @@ if (!DeviceManager::approved($token)) {
echo json_encode(array( echo json_encode(array(
'state' => 'unsuccess', 'state' => 'unsuccess',
'errorMSG' => "Unaproved Device", 'errorMSG' => "Unaproved Device",
)); ), JSON_PRETTY_PRINT);
exit(); exit();
} }
@ -251,7 +251,7 @@ if ($values != null || $values != "") {
if (!in_array($subDevicesTypeList, ['on/off', 'door', 'water'])) { if (!in_array($subDevicesTypeList, ['on/off', 'door', 'water'])) {
$jsonAnswer['device']['sleepTime'] = $device['sleep_time']; $jsonAnswer['device']['sleepTime'] = $device['sleep_time'];
} }
echo json_encode($jsonAnswer); echo json_encode($jsonAnswer, JSON_PRETTY_PRINT);
header($_SERVER["SERVER_PROTOCOL"]." 200 OK"); header($_SERVER["SERVER_PROTOCOL"]." 200 OK");
} else { } else {
//Vypis //Vypis
@ -282,7 +282,7 @@ if ($values != null || $values != "") {
'state' => 'succes', 'state' => 'succes',
'value' => $subDeviceLastReordValue, 'value' => $subDeviceLastReordValue,
'command' => $command, 'command' => $command,
)); ), JSON_PRETTY_PRINT);
header($_SERVER["SERVER_PROTOCOL"]." 200 OK"); header($_SERVER["SERVER_PROTOCOL"]." 200 OK");
} }