Login #1

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

View File

@ -8,8 +8,7 @@ class User {
private string $password; private string $password;
private BancaDati $db; private BancaDati $db;
public function __construct(string $username) { public function __construct() {
$this->username = $username;
$db = new BancaDati(); $db = new BancaDati();
return $this; return $this;
} }
@ -17,9 +16,15 @@ class User {
public function exists() { public function exists() {
return true; return true;
} }
public function login(string $password) : string { public function loginWithUsername(string $username, string $password) : string {
// select user $userObject = $this->db->select("utente", ["username" => $username]);
// $this->db->select() var_dump($userObject);
if(!$userObject){
return false;
}
return "token"; return "token";
} }
public function loginWithToken(string $token){
}
} }

View File

@ -27,14 +27,25 @@ $app->get("/", function (array $req, Response $res) {
$app->get("/user", function (array $req, Response $res) { $app->get("/user", function (array $req, Response $res) {
$res->send("user"); $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"]); $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"]; $username = $req["body"]["username"];
$password = $req["body"]["username"]; $password = $req["body"]["password"];
$user = new User($username).login($password);
$user = $db->select("utente", ["nomeUtente" => $username]);
var_dump($user);
return;
$user = new User();
$user->loginWithUsername($username, $password);
return;
if(isset($user)){ if(isset($user)){
setcookie($user->token, "TOKEN"); setcookie($user->token, "TOKEN");