fix: refactor

This commit is contained in:
Johannes Kantz 2023-01-23 05:31:35 +01:00
parent c717e5c4e9
commit e8775385cf

View File

@ -11,8 +11,7 @@ use Router\Router;
use Router\Route; use Router\Route;
use BancaDati\BancaDati; use BancaDati\BancaDati;
abstract class HTTP_STATUS_CODE abstract class HTTP_STATUS_CODE {
{
const OK = 200; const OK = 200;
const CREATED = 201; const CREATED = 201;
const BAD_REQUEST = 400; const BAD_REQUEST = 400;
@ -41,8 +40,9 @@ $app->use("/", function (array &$req, Response $res) {
* Home * Home
*/ */
$app->get("/", function (array $req, Response $res) use ($db) { $app->get("/", function (array $req, Response $res) use ($db) {
$res->send("Hello World"); $res->json(["message" => "",
//var_dump($req["user"]); "name" => "Shopping List",
"authors" => "Simon Bock, Johannes Kantz & Malte Schulze Hobeling"]);
}); });
/* /*
@ -77,9 +77,9 @@ $app->post("/login", function( array $req, Response $res) use ($db) {
if ($usertoken) { if ($usertoken) {
setcookie("TOKEN", $usertoken, time() + 3600); // 1h setcookie("TOKEN", $usertoken, time() + 3600); // 1h
$res->send("Login successful" . "token: " . $usertoken); $res->json(["message" => "Login successful", "token" => $usertoken]);
} else { } else {
$res->send("Login failed", HTTP_STATUS_CODE::FORBIDDEN); $res->json(["message" => "Login failed"], HTTP_STATUS_CODE::FORBIDDEN);
} }
}); });