From e25fcb07eafbe853f727c1565002a3f015a9384a Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 5 Oct 2026 10:31:39 +0200 Subject: [PATCH] fix #91 LoginController: pass the last authentication error and username to the login template The EasyAdmin login template displays the error with the `error` variable and fills the email with `last_username`: after a failed login, no message was displayed and the email had to be typed again. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + src/Controller/Admin/Security/LoginController.php | 5 ++++- tests/Functional/SecurityTest.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae47a73..49306f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Latest ## Fixes * [#89](https://github.com/cleverage/ui-process-bundle/issues/89) `ProcessConfigurationsManager`: resolve the `ui.default` option with a normalizer instead of nested options defined with `setDefault()` (deprecated since symfony/options-resolver 7.3, removed in 8.0). With Symfony 8, a process launched with the UI form (`ui_launch_mode: form`) without `ui.default` no longer fails (`Cannot use object of type Closure as array`), and `ui.default` is validated again. Add tests. +* [#91](https://github.com/cleverage/ui-process-bundle/issues/91) `LoginController`: pass `error` and `last_username` (`AuthenticationUtils`) to the login template, so that a failed login displays the error message and keeps the email. Test updated. v3.0.2 ------ diff --git a/src/Controller/Admin/Security/LoginController.php b/src/Controller/Admin/Security/LoginController.php index c55b1e0..b6ee314 100644 --- a/src/Controller/Admin/Security/LoginController.php +++ b/src/Controller/Admin/Security/LoginController.php @@ -16,17 +16,20 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class LoginController extends AbstractController { #[Route('/process/login', name: 'process_login')] - public function __invoke(): Response + public function __invoke(AuthenticationUtils $authenticationUtils): Response { return $this->render( '@CleverAgeUiProcess/admin/login.html.twig', [ 'page_title' => 'Login', 'target_path' => '/process', + 'error' => $authenticationUtils->getLastAuthenticationError(), + 'last_username' => $authenticationUtils->getLastUsername(), ] ); } diff --git a/tests/Functional/SecurityTest.php b/tests/Functional/SecurityTest.php index 2dd0eff..6fd0e18 100644 --- a/tests/Functional/SecurityTest.php +++ b/tests/Functional/SecurityTest.php @@ -125,6 +125,10 @@ public function testLoginWithAnInvalidPassword(): void $this->client->submit($form); self::assertResponseRedirects('http://localhost/process/login'); + $crawler = $this->client->followRedirect(); + self::assertSelectorTextContains('.alert-danger', 'Invalid credentials.'); + self::assertSame('admin@example.com', $crawler->filter('#username')->attr('value')); + $this->client->request('GET', '/process'); self::assertResponseRedirects('http://localhost/process/login'); }