Login #1

Merged
PBS2H21ASH merged 15 commits from feat/login into don 2023-01-18 08:40:26 +01:00
2 changed files with 15 additions and 3 deletions
Showing only changes of commit a887921e5d - Show all commits

View File

@ -38,6 +38,16 @@ class User {
return $this->token; return $this->token;
} }
public function loginWithToken(string $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;
} }
} }

View File

@ -12,16 +12,18 @@ use BancaDati\BancaDati;
$app = new Router("/DirektiveDesDons"); $app = new Router("/DirektiveDesDons");
$db = new BancaDati(); $db = new BancaDati();
$app->use("/", function (array $req, Response $res) { $app->use("/", function (array &$req, Response $res) {
if(isset($_COOKIE["TOKEN"])){ if(isset($_COOKIE["TOKEN"])){
// user mit token finden und im req übergeben // 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) { $app->get("/", function (array $req, Response $res) {
$res->send("Hello World"); $res->send("Hello World");
var_dump($req["user"]);
}); });
$app->get("/user", function (array $req, Response $res) { $app->get("/user", function (array $req, Response $res) {