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."
|
"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
|
// Check if request is internal or external
|
||||||
if ($this->internal) {
|
if ($this->internal) {
|
||||||
$this->response = $return;
|
$this->response = $return;
|
||||||
|
return;
|
||||||
}else{
|
}else{
|
||||||
http_response_code($status);
|
http_response_code($status);
|
||||||
header("Content-Type: application/json; charset=UTF-8");
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ if (!isset($input["username"]) || !isset($input["password"])) {
|
|||||||
"error" => "missing_fields",
|
"error" => "missing_fields",
|
||||||
"error_text" => "Some fields are missing"
|
"error_text" => "Some fields are missing"
|
||||||
], true);
|
], true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $input["username"];
|
$username = $input["username"];
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,8 @@ if (!isset($input["name"]) || !isset($input["text"])) {
|
|||||||
$api->answer(400, [
|
$api->answer(400, [
|
||||||
"error" => "missing_fields",
|
"error" => "missing_fields",
|
||||||
"error_text" => "Some fields are missing"
|
"error_text" => "Some fields are missing"
|
||||||
]);
|
], true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$html_allowed = $api->getSetting("allow_html");
|
$html_allowed = $api->getSetting("allow_html");
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ if (!$result) {
|
|||||||
"entrys" => [],
|
"entrys" => [],
|
||||||
"empty" => true
|
"empty" => true
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($result as $row) {
|
foreach($result as $row) {
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ require_once API_DIR . "api.php";
|
|||||||
$api = new gbAPI(false, $internal);
|
$api = new gbAPI(false, $internal);
|
||||||
|
|
||||||
// Get App Name
|
// Get App Name
|
||||||
$command = "SELECT name, value FROM settings WHERE name = :name";
|
$result = $api->getSetting("application_name");
|
||||||
$result = $api->dbCommand($command, true, true, [":name" => "application_name"]);
|
|
||||||
|
|
||||||
$api->answer(200, [
|
$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" => "missing_fields",
|
||||||
"error_text" => "Some fields are missing"
|
"error_text" => "Some fields are missing"
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if application already configurated
|
// Check if application already configurated
|
||||||
@@ -26,6 +27,7 @@ if (is_file(APP_PATH . "database.db")) {
|
|||||||
"error" => "already_configurated",
|
"error" => "already_configurated",
|
||||||
"error_text" => "The application is already configurated."
|
"error_text" => "The application is already configurated."
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check PDO drivers
|
// Check PDO drivers
|
||||||
@@ -34,6 +36,7 @@ if (!extension_loaded("pdo_sqlite") || !extension_loaded("sqlite3")) {
|
|||||||
"error" => "missing_drives",
|
"error" => "missing_drives",
|
||||||
"error_text" => "Please install the extensions pdo_sqlite and sqlite3."
|
"error_text" => "Please install the extensions pdo_sqlite and sqlite3."
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $input["username"];
|
$username = $input["username"];
|
||||||
@@ -46,6 +49,7 @@ if ($password !== $password_repeat) {
|
|||||||
"error" => "passwords_dont_match",
|
"error" => "passwords_dont_match",
|
||||||
"error_text" => "The passwords does not match."
|
"error_text" => "The passwords does not match."
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash Password
|
// 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"]);
|
$html = file_get_contents(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"]);
|
||||||
|
|
||||||
if ($showAppName) {
|
if ($showAppName) {
|
||||||
$app_name = file_get_contents("http://" . APP_DOMAIN . "/api/settings/appname.php");
|
$call = new APICall("settings/appname.php");
|
||||||
$app_name = json_decode($app_name, true);
|
$response = $call->response;
|
||||||
$app_name = $app_name["data"]["application_name"];
|
$app_name = $response["data"]["application_name"];
|
||||||
|
|
||||||
$html = str_replace("%appname%", $app_name, $html);
|
$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