diff --git a/sources/AppBundle/Association/Form/LoginType.php b/sources/AppBundle/Association/Form/LoginType.php new file mode 100644 index 000000000..ec203c793 --- /dev/null +++ b/sources/AppBundle/Association/Form/LoginType.php @@ -0,0 +1,51 @@ +> + */ +class LoginType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('utilisateur', TextType::class, [ + 'label' => "Email ou nom d'utilisateur", + ]) + ->add('mot_de_passe', PasswordType::class, [ + 'label' => 'Mot de passe', + ]) + ->add('_target_path', HiddenType::class) + ->add('submit', SubmitType::class, ['label' => 'Se connecter']) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'csrf_field_name' => '_csrf_token', + 'csrf_token_id' => 'authenticate', + ]); + } + + public function getBlockPrefix(): string + { + return ''; + } +} diff --git a/sources/AppBundle/Controller/Auth/LoginAction.php b/sources/AppBundle/Controller/Auth/LoginAction.php index 71c5b7add..d272c8aff 100644 --- a/sources/AppBundle/Controller/Auth/LoginAction.php +++ b/sources/AppBundle/Controller/Auth/LoginAction.php @@ -4,15 +4,20 @@ namespace AppBundle\Controller\Auth; +use AppBundle\Association\Form\LoginType; use AppBundle\Twig\ViewRenderer; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; final readonly class LoginAction { public function __construct( private AuthenticationUtils $authenticationUtils, + private FormFactoryInterface $formFactory, + private UrlGeneratorInterface $urlGenerator, private ViewRenderer $view, ) {} @@ -29,13 +34,17 @@ public function __invoke(Request $request): Response $noDomain = parse_url($targetUri, PHP_URL_HOST) === null; $targetPath = $targetUri !== $actualUrl && $noDomain ? $targetUri : null; + // Le formulaire n'est pas soumis à Symfony : c'est le firewall qui intercepte le POST sur cette même URL. + $form = $this->formFactory->create(LoginType::class, [ + 'utilisateur' => $lastUsername, + '_target_path' => $targetPath, + ], [ + 'action' => $this->urlGenerator->generate('app_login'), + ]); + return $this->view->render('site/auth/login.html.twig', [ - 'last_username' => $lastUsername, + 'form' => $form->createView(), 'error' => $error, - 'target_path' => $targetPath, - 'title' => 'Connexion', - 'page' => 'connexion', - 'class' => 'panel-page', ]); } } diff --git a/templates/site/auth/login.html.twig b/templates/site/auth/login.html.twig index 34a0d83f1..c6ae1df19 100644 --- a/templates/site/auth/login.html.twig +++ b/templates/site/auth/login.html.twig @@ -1,45 +1,40 @@ {% extends 'layouts/site.html.twig' %} +{% form_theme form 'form_themes/tailwind.html.twig' %} -{% block content %} - -