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 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){
}
}

View File

@ -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");