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.
67 lines
1.6 KiB
67 lines
1.6 KiB
<?php
|
|
|
|
|
|
class MdlUser{
|
|
|
|
private $con;
|
|
|
|
public function __construct(){
|
|
|
|
global $rep,$vues,$dsn, $login, $password;
|
|
$this->con = new Connection($dsn, $login, $password);
|
|
}
|
|
|
|
public function connexion($login){
|
|
$_SESSION['role'] = 'Utilisateur';
|
|
$_SESSION['login'] = $login;
|
|
}
|
|
|
|
public function signUp($login, $mdp){
|
|
$gate=new UserGateway($this->con);
|
|
|
|
$result=$gate->insert($login, $mdp);
|
|
if ($result==true){
|
|
$_SESSION['role'] = 'Utilisateur';
|
|
$_SESSION['username'] = $login;
|
|
}
|
|
}
|
|
|
|
public function delete(User $user){
|
|
$gate=new UserGateway($this->con);
|
|
$gate->delete($user);
|
|
}
|
|
|
|
public function update(User $user, string $username, string $password){
|
|
$user->setUsername($username);
|
|
$user->setPassword($password);
|
|
$gate=new UserGateway($this->con);
|
|
$gate->update($user);
|
|
}
|
|
|
|
function deconnection(){
|
|
session_unset();
|
|
session_destroy();
|
|
$_SESSION = array();
|
|
}
|
|
|
|
public function existUser(string $name):bool{
|
|
$gate=new UserGateway($this->con);
|
|
if($gate->findByName($name) != null){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getPasswordHash(string $usr){
|
|
$gate=new UserGateway($this->con);
|
|
return $gate->getHashedPassword($usr);
|
|
}
|
|
|
|
public function findByName(string $usr){
|
|
$gate=new UserGateway($this->con);
|
|
$result=$gate->findByName($usr);
|
|
return new User($result['id'], $usr, $result['password']);
|
|
}
|
|
|
|
}
|
|
?>
|