diff --git a/Documentation/Dokumentation.md b/Documentation/Dokumentation.md index a070207..37c99aa 100644 --- a/Documentation/Dokumentation.md +++ b/Documentation/Dokumentation.md @@ -13,7 +13,7 @@ Eine auflistung von allen Funktionen und API-Endpunkten mit Erklärung. ### User erstellen ```shell -POST 127.0.0.1/DirektiveDesDons/signup +POST 127.0.0.1/DirektiveDesDons/user BODY { diff --git a/index.php b/index.php index b9cb119..5c4cddd 100644 --- a/index.php +++ b/index.php @@ -48,22 +48,22 @@ $app->get("/", function (array $req, Response $res) use ($db) { /* * User */ -$app->get("/user", function (array $req, Response $res) { - if (isset($req["user"])) { - $res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]); - } else { - $res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]); - } -}); -$app->post("/signup", function (array $req, Response $res) use ($db) { - $newUsername = $req["body"]["username"]; - $newPassword = $req["body"]["password"]; - $newEmail = $req["body"]["email"]; - $db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]); - - $res->send("Account Created", HTTP_STATUS_CODE::CREATED); -}); +$app->route("/user") + ->get(function (array $req, Response $res) { + if (isset($req["user"])) { + $res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]); + } else { + $res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]); + } + }) + ->post(function (array $req, Response $res) use ($db) { + $newUsername = $req["body"]["username"]; + $newPassword = $req["body"]["password"]; + $newEmail = $req["body"]["email"]; + $db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]); + $res->send("Account Created", HTTP_STATUS_CODE::CREATED); + }); $app->post("/login", function (array $req, Response $res) use ($db) { $username = $req["body"]["username"]; $password = $req["body"]["password"];