Refactor API structure: update internal handling, enhance input retrieval, and improve template loading
This commit is contained in:
1 parent
a33de15f0c
commit
9cb50d7d28
13 files changed
+181
-95
No files matched your search
+12
-13
@@ -1,18 +1,17 @@
|
||||
<?php
|
||||
// Load Main Libary
|
||||
require "../api.php";
|
||||
|
||||
$api = new gbAPI(false);
|
||||
|
||||
// Check Request body
|
||||
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
||||
$api->answer(400, [
|
||||
"error" => "false_request_method",
|
||||
"error_text" => "Only POST allowed"
|
||||
]);
|
||||
// Set internal to false so that the answer goes to the client
|
||||
if (!isset($internal)) {
|
||||
$internal = false;
|
||||
define("API_DIR", "../");
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
// Load Main Libary
|
||||
require API_DIR . "api.php";
|
||||
|
||||
$api = new gbAPI(false, $internal);
|
||||
|
||||
// Check Request body
|
||||
$input = $api->getInput();
|
||||
|
||||
if (!isset($input["username"]) || !isset($input["password"]) || !isset($input["password_repeat"])) {
|
||||
$api->answer(400, [
|
||||
@@ -94,12 +93,12 @@ $env = "";
|
||||
|
||||
$cookie_token = bin2hex(random_bytes(32));
|
||||
$env .= "COOKIE_TOKEN_SIGNATURE=" . $cookie_token . "\n";
|
||||
$env .= "COOKIE_TOKEN_LIFETIME=86400\n";
|
||||
|
||||
$api_token = bin2hex(random_bytes(32));
|
||||
$env .= "API_TOKEN_SIGNATURE=" . $api_token . "\n";
|
||||
|
||||
$env .= "DB_FILE=database.db";
|
||||
$env .= "COOKIE_TOKEN_LIFETIME=86400";
|
||||
|
||||
file_put_contents(APP_PATH . ".env", $env);
|
||||
|
||||
|
||||
Reference in new issue
Block a user