complément logs et exceptions #20

Merged
mlamalle merged 4 commits from issue-19 into develop 2024-04-29 11:33:17 +02:00
6 changed files with 23 additions and 32 deletions
Showing only changes of commit 0791727694 - Show all commits

View File

@ -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)) {

View File

@ -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() . ';';
}
}

View File

@ -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';
}
}

View File

@ -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();

View File

@ -7,11 +7,7 @@
<body>
<trans-unit id="fXVg5Zq" resname="error.login">
<source>error.login</source>
<target>Incorrect login</target>
</trans-unit>
<trans-unit id="8VJKwdK" resname="error.password">
<source>error.password</source>
<target>Incorrect password</target>
<target>Incorrect login or password</target>
</trans-unit>
<trans-unit id="36t19qm" resname="error.sql_login">
<source>error.sql_login</source>

View File

@ -7,11 +7,7 @@
<body>
<trans-unit id="fXVg5Zq" resname="error.login">
<source>error.login</source>
<target>Login incorrect ou inconnu</target>
</trans-unit>
<trans-unit id="8VJKwdK" resname="error.password">
<source>error.password</source>
<target>Mot de passe incorrect</target>
<target>Login ou mot de passe inconnu</target>
</trans-unit>
<trans-unit id="36t19qm" resname="error.sql_login">
<source>error.sql_login</source>