feat (gestion exceptions) #19: traitement retour: typage, un seul message pour erreur login ou mdp
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
Details
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
Details
This commit is contained in:
parent
3e45119684
commit
0791727694
|
@ -29,11 +29,11 @@ class SecurityController extends AbstractController
|
||||||
$error = $authenticationUtils->getLastAuthenticationError();
|
$error = $authenticationUtils->getLastAuthenticationError();
|
||||||
if ($error) {
|
if ($error) {
|
||||||
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_LOGIN)) {
|
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);
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_LOGIN);
|
||||||
}
|
}
|
||||||
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PASSWORD)) {
|
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);
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PASSWORD);
|
||||||
}
|
}
|
||||||
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) {
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) {
|
||||||
|
|
|
@ -69,16 +69,17 @@ class SQLLoginRequest
|
||||||
public function getRequestScope()
|
public function getRequestScope()
|
||||||
{
|
{
|
||||||
$scope = '';
|
$scope = '';
|
||||||
if ($this->config[self::DATA_TO_FETCH]) {
|
if (!$this->config[self::DATA_TO_FETCH]) {
|
||||||
|
throw new NullDataToFetchException();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
||||||
$scope .= $data.',';
|
$scope .= $data . ',';
|
||||||
}
|
}
|
||||||
// On enlève la dernière virgule
|
// On enlève la dernière virgule
|
||||||
$scope = substr($scope, 0, -1);
|
$scope = substr($scope, 0, -1);
|
||||||
|
|
||||||
return 'SELECT '.$scope.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';';
|
return 'SELECT ' . $scope . ' FROM ' . $this->getTableName() . ' WHERE ' . $this->getLoginColumnName() . ' = :' . $this->getLoginColumnName() . ';';
|
||||||
}
|
|
||||||
throw new NullDataToFetchException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,9 +90,9 @@ class SQLLoginRequest
|
||||||
{
|
{
|
||||||
$fields = $this->getPasswordColumnName();
|
$fields = $this->getPasswordColumnName();
|
||||||
if (!empty($this->getSaltColumnName())) {
|
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() . ';';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,12 @@ use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||||
use App\SQLLogin\Exception\SecurityPatternConfigurationException;
|
use App\SQLLogin\Exception\SecurityPatternConfigurationException;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
|
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
|
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\Badge\UserBadge;
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
|
||||||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
||||||
|
|
||||||
class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||||
|
@ -54,19 +52,19 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||||
return self::LOGIN_ROUTE === $request->attributes->get('_route') && $request->isMethod('POST');
|
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);
|
$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');
|
$form = $request->request->get('login');
|
||||||
$login = $form['login'];
|
$login = $form['login'];
|
||||||
|
@ -120,6 +118,6 @@ class SQLLoginUserAuthenticator extends AbstractLoginFormAuthenticator
|
||||||
|
|
||||||
protected function getLoginUrl(Request $request): string
|
protected function getLoginUrl(Request $request): string
|
||||||
{
|
{
|
||||||
return $this->baseUrl.'/login';
|
return $this->baseUrl . '/login';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SQLLoginService extends AbstractController
|
||||||
return $datas;
|
return $datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchPassword(string $login)
|
public function fetchPassword($login): array|bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbh = $this->getConnection();
|
$dbh = $this->getConnection();
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="fXVg5Zq" resname="error.login">
|
<trans-unit id="fXVg5Zq" resname="error.login">
|
||||||
<source>error.login</source>
|
<source>error.login</source>
|
||||||
<target>Incorrect login</target>
|
<target>Incorrect login or password</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="8VJKwdK" resname="error.password">
|
|
||||||
<source>error.password</source>
|
|
||||||
<target>Incorrect password</target>
|
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="36t19qm" resname="error.sql_login">
|
<trans-unit id="36t19qm" resname="error.sql_login">
|
||||||
<source>error.sql_login</source>
|
<source>error.sql_login</source>
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="fXVg5Zq" resname="error.login">
|
<trans-unit id="fXVg5Zq" resname="error.login">
|
||||||
<source>error.login</source>
|
<source>error.login</source>
|
||||||
<target>Login incorrect ou inconnu</target>
|
<target>Login ou mot de passe inconnu</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="8VJKwdK" resname="error.password">
|
|
||||||
<source>error.password</source>
|
|
||||||
<target>Mot de passe incorrect</target>
|
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="36t19qm" resname="error.sql_login">
|
<trans-unit id="36t19qm" resname="error.sql_login">
|
||||||
<source>error.sql_login</source>
|
<source>error.sql_login</source>
|
||||||
|
|
Loading…
Reference in New Issue