generated from Templates_CodeFirst/templateHtmlCss
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
<?php
|
|
|
|
|
|
class UserGateway
|
|
{
|
|
private $con;
|
|
|
|
public function __construct(Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(User $u){
|
|
try{
|
|
$query = "INSERT INTO Utilisateur VALUES (null, :username, :password)";
|
|
$this->con->executeQuery($query, array(':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
|
|
}
|
|
catch(PDOException $Exception){
|
|
echo 'erreur';
|
|
echo $Exception->getMessage();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
public function delete(User $u): void{
|
|
$query = "DELETE FROM Utilisateur where id=:id";
|
|
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT)));
|
|
}
|
|
|
|
public function update(User $u): void{
|
|
$query = "UPDATE Utilisateur SET username=:username, password=:password WHERE id=:id";
|
|
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT), ':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
|
|
}
|
|
|
|
public function findByName(string $username): array{
|
|
$query = "SELECT * FROM Utilisateur WHERE username=:username";
|
|
$this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR)));
|
|
$results=$this->con->getResults();
|
|
return $results;
|
|
}
|
|
|
|
public function getLastId(): array{
|
|
$query = "SELECT max(id) as oldId FROM Utilisateur";
|
|
$this->con->executeQuery($query, array());
|
|
$results=$this->con->getResults();
|
|
return $results;
|
|
}
|
|
|
|
function getHashedPassword(string $usrname):?string{
|
|
$truePasswd=null;
|
|
$query="SELECT password FROM Utilisateur WHERE name=:name";
|
|
$this->con->executeQuery($query,array('name'=>array($usrname,PDO::PARAM_STR)));
|
|
$results=$co->getResults();
|
|
foreach($res as $row){
|
|
$results=$row['pwd'];
|
|
}
|
|
return $truePasswd;
|
|
}
|
|
}
|
|
|
|
?>
|