From 148f95087db24287b31599823af0216ca383dcf0 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:41:58 +0100 Subject: [PATCH] add: login begin --- index.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.php b/index.php index 224a190..b7c60de 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ require_once("Router/Router.php"); require_once("Router/Response.php"); require_once("BancaDati/BancaDati.php"); +require_once("User.php"); use Router\Response; use Router\Router; @@ -11,6 +12,13 @@ use BancaDati\BancaDati; $app = new Router("/DirektiveDesDons"); $db = new BancaDati(); +$app->use("/", function (array $req, Response $res) { + if(isset($_COOKIE["TOKEN"])){ + // user mit token finden und im req übergeben + $user = new User(""); + + } +}); $app->get("/", function (array $req, Response $res) { $res->send("Hello World"); @@ -23,4 +31,17 @@ $app->get("/user/:id", function (array $req, Response $res) { $res->send("user " . $req["params"]["id"]); }); +$app->post("/login", function( array $req, Response $res) { + $username = $req["body"]["username"]; + $password = $req["body"]["username"]; + $user = new User($username).login($password); + + if(isset($user)){ + setcookie($user->token, "TOKEN"); + $res->send("Login successful", 200); + }else{ + $res->send("Login failed", 403); + } +}); + $app->start(); \ No newline at end of file