From a887921e5d0e8b61acd36848a629cd933321c4d9 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Thu, 12 Jan 2023 15:22:32 +0100 Subject: [PATCH] quick safe --- User.php | 10 ++++++++++ index.php | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/User.php b/User.php index b3cc7ec..203368b 100644 --- a/User.php +++ b/User.php @@ -38,6 +38,16 @@ class User { return $this->token; } public function loginWithToken(string $token){ + $userObject = $this->db->select("utente", ["gettone" => $token]); + if(!$userObject){ + return false; + } + $this->id = $userObject["id"]; + $this->username = $userObject["nomeUtente"]; + $this->email = $userObject["email"]; + $this->password = $userObject["parolaDordine"]; + $this->token = $token; + return $this; } } \ No newline at end of file diff --git a/index.php b/index.php index c913f1f..756988a 100644 --- a/index.php +++ b/index.php @@ -12,16 +12,18 @@ use BancaDati\BancaDati; $app = new Router("/DirektiveDesDons"); $db = new BancaDati(); -$app->use("/", function (array $req, Response $res) { +$app->use("/", function (array &$req, Response $res) { if(isset($_COOKIE["TOKEN"])){ // user mit token finden und im req übergeben - $user = new User(""); - + $user = new User(); + $user->loginWithToken($_COOKIE["TOKEN"]); + $req["user"] = $user; } }); $app->get("/", function (array $req, Response $res) { $res->send("Hello World"); + var_dump($req["user"]); }); $app->get("/user", function (array $req, Response $res) {