Enhance API functionality: add token generation methods, implement entry management, and improve setup process with settings storage

This commit is contained in:
marc-go committed 2026-10-06 14:46:25 +02:00
1 parent 8ef5f7a941
commit 9316818753
9 files changed
+248 -25

No files matched your search

+39 -1
View File
@@ -21,6 +21,14 @@ if (!isset($input["username"]) || !isset($input["password"]) || !isset($input["p
]);
}
// Check if application already configurated
if (is_file(APP_PATH . "database.db")) {
$api->answer(503, [
"error" => "already_configurated",
"error_text" => "The application is already configurated."
]);
}
$username = $input["username"];
$password = $input["password"];
$password_repeat = $input["password_repeat"];
@@ -56,5 +64,35 @@ $command = "INSERT INTO users (username, password, owner) VALUES (:username, :pa
$stmt = $db->prepare($command);
$stmt->execute([":username" => $username, ":password" => $hash, ":owner" => 1]);
$api->answer(200);
// INSERT SETTINGS
$command = "INSERT INTO settings (name, value) VALUES (:name, :value)";
$settings = [
":application_name" => "",
":allow_html" => "false",
":approve_entrys" => "true",
":allow_new_entrys" => "true"
];
foreach ($settings as $key => $value) {
$stmt = $db->prepare($command);
$stmt->execute([$key => $value]);
}
// WRITE .env AND GENERATE SECRETS
$env = "";
$cookie_token = bin2hex(random_bytes(32));
$env .= "COOKIE_TOKEN_SIGNATURE=" . $cookie_token;
$api_token = bin2hex(random_bytes(32));
$env .= "API_TOKEN_SIGNATURE=" . $api_token;
$env .= "DB_FILE=database.db";
file_put_contents(APP_PATH . ".env", $env);
// RETURN SUCCESS MESSAGE
$api->answer(200);