From 34b1b391d4b03659a96f868857c230002b351514 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Mon, 9 Sep 2024 17:57:00 +0200 Subject: More updates --- src/index.php | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 62a300a..8e2ce4e 100644 --- a/src/index.php +++ b/src/index.php @@ -1,13 +1,72 @@ getMessage()), + ]); + exit; +} + $db->ensureTable(User::class); $db->ensureTable(Topic::class); $db->ensureTable(Post::class); + +$superuser = new User(); +$superuser->id = "SUPERUSER"; +if (!$db->fetch($superuser)) { + $superUserPassword = base64_encode(random_bytes(12)); + + $superuser->name = "superuser"; + $superuser->passwordHash = password_hash($superUserPassword, PASSWORD_DEFAULT); + $superuser->displayName = "SuperUser"; + $superuser->created = new \DateTimeImmutable(); + + $db->insert($superuser); + + Messaging::info([ + Messaging::bold("Superuser account created"), + [ + "Username" => $superuser->name, + "Password" => $superUserPassword, + ], + "Please note that the password can only be shown this time, so please note it down!", + ]); + exit; +} + +// initialization finished + +if ($_action === "auth") { + RequestUtils::ensureRequestMethod("POST"); + // TODO Login logic +} elseif ($_action === null) { + echo "Hello"; +} else { + http_response_code(404); + Messaging::error("Invalid or unknown action $_action"); +} -- cgit v1.2.3