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