Enhance API error handling and response structure; update app name retrieval method
This commit is contained in:
1 parent
95f8e22f11
commit
eb67458ab1
9 files changed
+38
-9
No files matched your search
+2
-1
@@ -40,7 +40,7 @@ class gbAPI {
|
||||
"error_text" => "Authentication failed."
|
||||
];
|
||||
|
||||
$this->answer($status, $data);
|
||||
$this->answer($status, $data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,7 @@ class gbAPI {
|
||||
// Check if request is internal or external
|
||||
if ($this->internal) {
|
||||
$this->response = $return;
|
||||
return;
|
||||
}else{
|
||||
http_response_code($status);
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
|
||||
@@ -18,6 +18,7 @@ if (!isset($input["username"]) || !isset($input["password"])) {
|
||||
"error" => "missing_fields",
|
||||
"error_text" => "Some fields are missing"
|
||||
], true);
|
||||
return;
|
||||
}
|
||||
|
||||
$username = $input["username"];
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ if (!isset($input["name"]) || !isset($input["text"])) {
|
||||
$api->answer(400, [
|
||||
"error" => "missing_fields",
|
||||
"error_text" => "Some fields are missing"
|
||||
]);
|
||||
], true);
|
||||
return;
|
||||
}
|
||||
|
||||
$html_allowed = $api->getSetting("allow_html");
|
||||
|
||||
@@ -21,6 +21,7 @@ if (!$result) {
|
||||
"entrys" => [],
|
||||
"empty" => true
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($result as $row) {
|
||||
|
||||
@@ -11,9 +11,8 @@ require_once API_DIR . "api.php";
|
||||
$api = new gbAPI(false, $internal);
|
||||
|
||||
// Get App Name
|
||||
$command = "SELECT name, value FROM settings WHERE name = :name";
|
||||
$result = $api->dbCommand($command, true, true, [":name" => "application_name"]);
|
||||
$result = $api->getSetting("application_name");
|
||||
|
||||
$api->answer(200, [
|
||||
"application_name" => $result[0]["value"]
|
||||
"application_name" => $result
|
||||
]);
|
||||
@@ -18,6 +18,7 @@ if (!isset($input["username"]) || !isset($input["password"]) || !isset($input["p
|
||||
"error" => "missing_fields",
|
||||
"error_text" => "Some fields are missing"
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if application already configurated
|
||||
@@ -26,6 +27,7 @@ if (is_file(APP_PATH . "database.db")) {
|
||||
"error" => "already_configurated",
|
||||
"error_text" => "The application is already configurated."
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check PDO drivers
|
||||
@@ -34,6 +36,7 @@ if (!extension_loaded("pdo_sqlite") || !extension_loaded("sqlite3")) {
|
||||
"error" => "missing_drives",
|
||||
"error_text" => "Please install the extensions pdo_sqlite and sqlite3."
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$username = $input["username"];
|
||||
@@ -46,6 +49,7 @@ if ($password !== $password_repeat) {
|
||||
"error" => "passwords_dont_match",
|
||||
"error_text" => "The passwords does not match."
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Hash Password
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// Set debug to true
|
||||
$debug = true;
|
||||
|
||||
// Load Main Library
|
||||
require "../main.php";
|
||||
|
||||
// Init Main Class
|
||||
$gb = new gb($debug);
|
||||
|
||||
// Load and init HTML Loader Library
|
||||
require FRONTEND_PATH . "html_loader.php";
|
||||
$htmlloader = new HTMLLoader();
|
||||
|
||||
// Check Login
|
||||
$call = new APICall("auth/isauth.php");
|
||||
$response = $call->response;
|
||||
|
||||
if (!isset($response["data"]["login"])) {
|
||||
$htmlloader->setPage("login");
|
||||
$htmlloader->show();
|
||||
}
|
||||
@@ -91,9 +91,9 @@ class HTMLLoader {
|
||||
$html = file_get_contents(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"]);
|
||||
|
||||
if ($showAppName) {
|
||||
$app_name = file_get_contents("http://" . APP_DOMAIN . "/api/settings/appname.php");
|
||||
$app_name = json_decode($app_name, true);
|
||||
$app_name = $app_name["data"]["application_name"];
|
||||
$call = new APICall("settings/appname.php");
|
||||
$response = $call->response;
|
||||
$app_name = $response["data"]["application_name"];
|
||||
|
||||
$html = str_replace("%appname%", $app_name, $html);
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,4 +40,4 @@ if ($response["data"]["empty"]) {
|
||||
}
|
||||
}
|
||||
|
||||
$htmlLoader->show(["%entrys%" => $html_block]);
|
||||
$htmlLoader->show(["%entrys%" => $html_block]);
|
||||
Reference in new issue
Block a user