Login #1
							
								
								
									
										15
									
								
								User.php
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								User.php
									
									
									
									
									
								
							@@ -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){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								index.php
									
									
									
									
									
								
							@@ -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");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user