Skip to content

Commit

Permalink
Merge pull request #182 from nucleos/fix-error-message
Browse files Browse the repository at this point in the history
Fix passing error to login form
  • Loading branch information
core23 committed Dec 28, 2020
2 parents 1d8523b + 2388b35 commit e61038f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Action/LoginAction.php
Expand Up @@ -16,6 +16,7 @@
use Nucleos\UserBundle\Event\GetResponseLoginEvent;
use Nucleos\UserBundle\Form\Type\LoginFormType;
use Nucleos\UserBundle\NucleosUserEvents;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -87,23 +88,25 @@ public function __invoke(Request $request): Response
$error = null;
}

if (!$error instanceof AuthenticationException) {
$error = null; // The value does not come from the security component.
}

$form = $this->formFactory->create(LoginFormType::class, null, [
'action' => $this->router->generate('nucleos_user_security_check'),
'method' => 'POST',
]);

if (!$error instanceof AuthenticationException) {
$error = null; // The value does not come from the security component.
} else {
$form->addError(new FormError($error->getMessageKey(), null, $error->getMessageData()));
}

// last username entered by the user
$lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);

return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', [
'last_username' => $lastUsername,
'form' => $form->createView(),
// TODO: Remove this fields with the next major release
'error' => null,
'error' => $error,
'csrf_token' => '',
]));
}
Expand Down

0 comments on commit e61038f

Please sign in to comment.