2022-12-09 17:31:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-12-13 15:46:24 +01:00
|
|
|
use App\Form\LoginType;
|
2022-12-14 16:38:46 +01:00
|
|
|
use App\Security\SQLLoginUserAuthenticator;
|
2022-12-09 17:31:07 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2022-12-13 15:46:24 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2022-12-09 17:31:07 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
2022-12-13 15:46:24 +01:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2022-12-09 17:31:07 +01:00
|
|
|
|
|
|
|
class SecurityController extends AbstractController
|
|
|
|
{
|
2022-12-13 15:46:24 +01:00
|
|
|
#[Route('/login', name: 'app_login')]
|
|
|
|
public function login(ParameterBagInterface $params, AuthenticationUtils $authenticationUtils, Request $request, TranslatorInterface $trans): Response
|
2022-12-09 17:31:07 +01:00
|
|
|
{
|
2022-12-13 15:46:24 +01:00
|
|
|
// Si l'utilisateur est déjà connecté on le renvoie sur la page du site demandeur
|
|
|
|
if ($this->getUser()) {
|
|
|
|
return new RedirectResponse($params->get('issuer_url'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// On fournit le form, mais il est traité par un authenticator
|
|
|
|
$loginForm = $this->createForm(LoginType::class, null);
|
2022-12-09 17:31:07 +01:00
|
|
|
$error = $authenticationUtils->getLastAuthenticationError();
|
|
|
|
if ($error) {
|
2022-12-14 16:38:46 +01:00
|
|
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_LOGIN)) {
|
2022-12-13 15:46:24 +01:00
|
|
|
$loginForm->get('login')->addError(new FormError($trans->trans('error.login', [], 'messages')));
|
2022-12-14 16:38:46 +01:00
|
|
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_LOGIN);
|
2022-12-13 15:46:24 +01:00
|
|
|
}
|
2022-12-14 16:38:46 +01:00
|
|
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PASSWORD)) {
|
2022-12-13 15:46:24 +01:00
|
|
|
$loginForm->get('password')->addError(new FormError($trans->trans('error.password', [], 'messages')));
|
2022-12-14 16:38:46 +01:00
|
|
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PASSWORD);
|
2022-12-13 15:46:24 +01:00
|
|
|
}
|
2022-12-14 16:38:46 +01:00
|
|
|
if ($request->getSession()->has(SQLLoginUserAuthenticator::ERROR_PDO)) {
|
2022-12-13 15:46:24 +01:00
|
|
|
$loginForm->addError(new FormError($trans->trans('error.pdo', [], 'messages')));
|
2022-12-14 16:38:46 +01:00
|
|
|
$request->getSession()->remove(SQLLoginUserAuthenticator::ERROR_PDO);
|
2022-12-13 15:46:24 +01:00
|
|
|
}
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 15:46:24 +01:00
|
|
|
return $this->render('login.html.twig', [
|
|
|
|
'loginForm' => $loginForm->createView(),
|
|
|
|
]);
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 15:46:24 +01:00
|
|
|
#[Route('/logout', name: 'logout')]
|
2022-12-09 17:31:07 +01:00
|
|
|
public function logout(Request $request)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|