diff --git a/User.php b/User.php index 0f61993..6d5dea9 100644 --- a/User.php +++ b/User.php @@ -8,8 +8,7 @@ class User { private string $password; private BancaDati $db; - public function __construct(string $username) { - $this->username = $username; + public function __construct() { $db = new BancaDati(); return $this; } @@ -17,9 +16,15 @@ class User { public function exists() { return true; } - public function login(string $password) : string { - // select user - // $this->db->select() + public function loginWithUsername(string $username, string $password) : string { + $userObject = $this->db->select("utente", ["username" => $username]); + var_dump($userObject); + if(!$userObject){ + return false; + } return "token"; } + public function loginWithToken(string $token){ + + } } \ No newline at end of file diff --git a/index.php b/index.php index b7c60de..bf767ce 100644 --- a/index.php +++ b/index.php @@ -27,14 +27,25 @@ $app->get("/", function (array $req, Response $res) { $app->get("/user", function (array $req, Response $res) { $res->send("user"); }); -$app->get("/user/:id", function (array $req, Response $res) { +$app->get("/user/:id", function (array $req, Response $res) use ($db) { + $db->select("utente", ["username" => $req["id"]]); $res->send("user " . $req["params"]["id"]); }); +$app->post("/createuser", function (array $req, Response $res) use ($db) { + $db->insert("utente", ["email" => "test@email.com", "parolaDordine" => "password", "nomeUtente" => "testuser"]); + $res->send("user "); +}); -$app->post("/login", function( array $req, Response $res) { +$app->post("/login", function( array $req, Response $res) use ($db) { $username = $req["body"]["username"]; - $password = $req["body"]["username"]; - $user = new User($username).login($password); + $password = $req["body"]["password"]; + + $user = $db->select("utente", ["nomeUtente" => $username]); + var_dump($user); + return; + $user = new User(); + $user->loginWithUsername($username, $password); + return; if(isset($user)){ setcookie($user->token, "TOKEN");