diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index cb525c5..6e4b75b 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -29,11 +29,11 @@ class SecurityController extends AbstractController $error = $authenticationUtils->getLastAuthenticationError(); if ($error) { if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_LOGIN)) { - $loginForm->get('login')->addError(new FormError($trans->trans('error.login', [], 'messages'))); + $loginForm->addError(new FormError($trans->trans('error.login', [], 'messages'))); $request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_LOGIN); } if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PASSWORD)) { - $loginForm->get('password')->addError(new FormError($trans->trans('error.password', [], 'messages'))); + $loginForm->addError(new FormError($trans->trans('error.login', [], 'messages'))); $request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PASSWORD); } if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) { diff --git a/src/SQLLogin/SQLLoginRequest.php b/src/SQLLogin/SQLLoginRequest.php index 80e8c9a..a71986f 100644 --- a/src/SQLLogin/SQLLoginRequest.php +++ b/src/SQLLogin/SQLLoginRequest.php @@ -69,16 +69,17 @@ class SQLLoginRequest public function getRequestScope() { $scope = ''; - if ($this->config[self::DATA_TO_FETCH]) { - foreach ($this->config[self::DATA_TO_FETCH] as $data) { - $scope .= $data.','; - } - // On enlève la dernière virgule - $scope = substr($scope, 0, -1); - - return 'SELECT '.$scope.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';'; + if (!$this->config[self::DATA_TO_FETCH]) { + throw new NullDataToFetchException(); } - throw new NullDataToFetchException(); + + foreach ($this->config[self::DATA_TO_FETCH] as $data) { + $scope .= $data . ','; + } + // On enlève la dernière virgule + $scope = substr($scope, 0, -1); + + return 'SELECT ' . $scope . ' FROM ' . $this->getTableName() . ' WHERE ' . $this->getLoginColumnName() . ' = :' . $this->getLoginColumnName() . ';'; } /** @@ -89,9 +90,9 @@ class SQLLoginRequest { $fields = $this->getPasswordColumnName(); if (!empty($this->getSaltColumnName())) { - $fields .= ', '.$this->getSaltColumnName(); + $fields .= ', ' . $this->getSaltColumnName(); } - return 'SELECT '.$fields.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';'; + return 'SELECT ' . $fields . ' FROM ' . $this->getTableName() . ' WHERE ' . $this->getLoginColumnName() . ' = :' . $this->getLoginColumnName() . ';'; } } diff --git a/src/Security/SQLLoginUserAuthenticator.php b/src/Security/SQLLoginUserAuthenticator.php index 842ad16..5db74cc 100644 --- a/src/Security/SQLLoginUserAuthenticator.php +++ b/src/Security/SQLLoginUserAuthenticator.php @@ -12,14 +12,12 @@ use App\SQLLogin\Exception\LoginElementsConfigurationException; use App\SQLLogin\Exception\SecurityPatternConfigurationException; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; -use Symfony\Component\Security\Http\Authenticator\Passport\Passport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator @@ -54,19 +52,19 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST'); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): RedirectResponse { - return new RedirectResponse($this->baseUrl.'/connect/login-accept'); + return new RedirectResponse($this->baseUrl . '/connect/login-accept'); } - public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): RedirectResponse { $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception); - return new RedirectResponse($this->baseUrl.'/login'); + return new RedirectResponse($this->baseUrl . '/login'); } - public function authenticate(Request $request): Passport + public function authenticate(Request $request): SelfValidatingPassport { $form = $request->request->get('login'); $login = $form['login']; @@ -120,6 +118,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator protected function getLoginUrl(Request $request): string { - return $this->baseUrl.'/login'; + return $this->baseUrl . '/login'; } } diff --git a/src/Service/SQLLoginService.php b/src/Service/SQLLoginService.php index 6b90546..ece37cb 100644 --- a/src/Service/SQLLoginService.php +++ b/src/Service/SQLLoginService.php @@ -51,7 +51,7 @@ class SQLLoginService extends AbstractController return $datas; } - public function fetchPassword(string $login) + public function fetchPassword($login): array|bool { try { $dbh = $this->getConnection(); diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 6df1993..8617499 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -7,11 +7,7 @@ error.login - Incorrect login - - - error.password - Incorrect password + Incorrect login or password error.sql_login diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index 662608c..39a5e8d 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -7,11 +7,7 @@ error.login - Login incorrect ou inconnu - - - error.password - Mot de passe incorrect + Login ou mot de passe inconnu error.sql_login