From 085533b299796d84a8a9640163de59b87a34922c Mon Sep 17 00:00:00 2001 From: rudy Date: Mon, 23 Sep 2024 17:02:01 +0200 Subject: [PATCH 1/2] =?UTF-8?q?chore=20(fetch=20datas)=20#39=20:=20fermetu?= =?UTF-8?q?re=20connexion=20sql=20apr=C3=A8s=20login$?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/SQLLoginService.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Service/SQLLoginService.php b/src/Service/SQLLoginService.php index 2011d60..ff43e78 100644 --- a/src/Service/SQLLoginService.php +++ b/src/Service/SQLLoginService.php @@ -26,6 +26,9 @@ class SQLLoginService extends AbstractController public function fetchDatas(string $login): array { + if (empty($login)) { + throw new Exception('Connexion échouée, le login ne peut pas être vide'); + } try { $dbh = $this->getConnection(); } catch (PDOException $e) { @@ -44,11 +47,15 @@ class SQLLoginService extends AbstractController $query = $dbh->prepare($request); $query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]); $datas = $query->fetch(PDO::FETCH_ASSOC); + $query->closeCursor(); } catch (PDOException $e) { $this->loggerInterface->critical($e->getMessage()); throw new DataToFetchConfigurationException($e->getMessage()); } + if (false === $datas) { + throw new Exception(sprintf('La requête sql "%s" a renvoyé un résultat incorrect.', $request)); + } return $datas; } @@ -75,7 +82,7 @@ class SQLLoginService extends AbstractController if (!$password) { throw new Exception('Une erreur est survenue lors de la récupération des données'); } - + return [ $password[$this->sqlLoginRequest->getPasswordColumnName()], isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null, From a1049a55a2c88e3fcd242ed13362f970792f8471 Mon Sep 17 00:00:00 2001 From: rudy Date: Tue, 24 Sep 2024 10:32:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?issue-39=20:=20close=20cursor=20pour=20requ?= =?UTF-8?q?=C3=AAte=20password?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SQLLogin/SQLLoginConnect.php | 5 ++--- src/Service/SQLLoginService.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SQLLogin/SQLLoginConnect.php b/src/SQLLogin/SQLLoginConnect.php index 86b55a6..c2a7cfe 100644 --- a/src/SQLLogin/SQLLoginConnect.php +++ b/src/SQLLogin/SQLLoginConnect.php @@ -13,9 +13,8 @@ class SQLLoginConnect extends AbstractController * Méthode qui crée l'unique instance de la classe * si elle n'existe pas encore puis la retourne. * - * @return SQLLoginConnect */ - public static function getInstance() + public static function getInstance(): SQLLoginConnect { if (is_null(self::$_instance)) { self::$_instance = new SQLLoginConnect(); @@ -24,7 +23,7 @@ class SQLLoginConnect extends AbstractController return self::$_instance; } - public function connect($urlDatabase, $dbUser, $dbPassword) + public function connect($urlDatabase, $dbUser, $dbPassword): PDO { return new PDO($urlDatabase, $dbUser, $dbPassword); } diff --git a/src/Service/SQLLoginService.php b/src/Service/SQLLoginService.php index ff43e78..46a23ab 100644 --- a/src/Service/SQLLoginService.php +++ b/src/Service/SQLLoginService.php @@ -75,6 +75,7 @@ class SQLLoginService extends AbstractController $query = $dbh->prepare($request); $query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]); $password = $query->fetch(PDO::FETCH_ASSOC); + $query->closeCursor(); } catch (PDOException $e) { $this->loggerInterface->critical($e->getMessage()); throw new LoginElementsConfigurationException($e->getMessage()); @@ -82,7 +83,6 @@ class SQLLoginService extends AbstractController if (!$password) { throw new Exception('Une erreur est survenue lors de la récupération des données'); } - return [ $password[$this->sqlLoginRequest->getPasswordColumnName()], isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,