diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 6480e6e..d5ef12a 100644 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -4,8 +4,8 @@ namespace controller; use config\Validation; use model\Connection; use model\LoginException; +use model\MdlAdmin; use model\MdlUser; -use model\UserGateway; class FrontController { @@ -79,8 +79,16 @@ class FrontController $_SESSION['pseudo'] = $_REQUEST['login']; header("Location: ."); } else { - $dVueErreur[] = "Connexion échouée"; - throw new LoginException("Connexion err"); + //todo : verifier si utilisateur existe dans User ou Admin au lieu de login les 2 a la fois + //voir si c'est un admin + $ug = new MdlAdmin(); + if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { + $_SESSION['pseudo'] = $_REQUEST['login']; + header("Location: ."); + } else { + $dVueErreur[] = "Connexion échouée"; + throw new LoginException("Connexion err"); + } } } else header("Location: ."); diff --git a/project/src/model/gateways/AdminGateway.php b/project/src/model/gateways/AdminGateway.php index f93de9d..291874b 100644 --- a/project/src/model/gateways/AdminGateway.php +++ b/project/src/model/gateways/AdminGateway.php @@ -2,7 +2,7 @@ namespace model; -class UserGateway +class AdminGateway { private \PDO $con; private \PDOStatement $stmt; diff --git a/project/src/model/mdl/MdlAdmin.php b/project/src/model/mdl/MdlAdmin.php new file mode 100644 index 0000000..e4f9ccb --- /dev/null +++ b/project/src/model/mdl/MdlAdmin.php @@ -0,0 +1,30 @@ +gw = new AdminGateway($this->con); + } + public function login(string $username, string $password): bool{ + return $this->gw->login($username, $password); + } +/* + public function setPseudo(int $id, string $pseudo): User{ + $this->gw->setPseudo($id, $pseudo); + return $this->getFromId($id); + } + + public function insertInvite(string $pseudo, string $idSession): User{ + $id = $this->gw->insertInvite($pseudo, $idSession); + return $this->getFromId($id); + } + + public function getFromId(int $id): User{ + $row = $this->gw->getFromId($id); + return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']); + }*/ +} \ No newline at end of file