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