diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php old mode 100644 new mode 100755 index a59b21a..ee61eee --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -2,24 +2,24 @@ namespace model; use config\Connection; -require_once('../config/Connection.php'); -require_once('Student.php'); +use http\Exception; +use model\UserGateway; class MdlStudent { + protected UserGateway $gtw; + + public function __construct($gtw){ + $this->gtw = $gtw; + + } public function connection($login, $mdp){ // 1. Nettoyage des données (vous pouvez utiliser des méthodes de nettoyage spécifiques) $cleanedLogin = strip_tags($login); $cleanedPassword = strip_tags($mdp); // 2. Appel Gateway pour vérifier les identifiants dans la base de données - $db = new Connection('mysql:host=localhost;dbname=ma_base', 'utilisateur', 'mot_de_passe'); - $query = $db->prepare('SELECT * FROM Student_ WHERE login = :login AND password = :password'); - $query->bindParam(':login', $cleanedLogin, PDO::PARAM_STR); - $query->bindParam(':password', $cleanedPassword, PDO::PARAM_STR); - $query->execute(); - - $student = $query->fetch(PDO::FETCH_ASSOC); + $student = $this->gtw->findUserByLoginPassword($cleanedLogin,$cleanedPassword); if ($student) { // L'authentification a réussi, ajouter le rôle et le login à la session @@ -28,7 +28,7 @@ class MdlStudent $_SESSION['login'] = $cleanedLogin; return true; } else { - // L'authentification a échoué + throw Exception('problème d\'authentification'); return false; } } @@ -45,9 +45,11 @@ class MdlStudent //Créer une classe nettoyer $login=Nettoyer::nettoyer_string($_SESSION['login']); $role=Nettoyer::nettoyer_string($_SESSION['role']); - return new Student($login,$role); + return self::$gtw->findUserByEmail($login); } else return null; } */ -} \ No newline at end of file + +} + diff --git a/Project/php/model/Student.php b/Project/php/model/Student.php deleted file mode 100644 index 7926066..0000000 --- a/Project/php/model/Student.php +++ /dev/null @@ -1,55 +0,0 @@ -nickname = $nickname; - $this->extraTime = $extraTime; - } - - /** - * @return bool - */ - public function isExtraTime(): bool - { - return $this->extraTime; - } - - /** - * @param bool $extraTime - */ - public function setExtraTime(bool $extraTime): void - { - $this->extraTime = $extraTime; - } - - /** - * @param String $nickname - */ - public function setNickname(string $nickname): void - { - $this->nickname = $nickname; - } - - public function getNickname(): string - { - return $this->nickname; - } - - - - -} \ No newline at end of file