0
votes

I am currently using FOSUserBundle in my Symfony 3.4 based project. We have some front-end design changes planned and I want to integrate the login form to the standard page template for non-logged in users to be able to login wherever they are on the app.

In my template file I am calling: {{ render(controller('FOSUserBundle:Security:login')) }}. This is correctly rendering the login form within the relevant pages.

However I have two problem I am unable to figure out how to overcome...

  1. If the user enters invalid credentials, how can I return the user to the page they were on rather than the /login route?

  2. How can I intercept the error message (Invalid credentials etc.)? I would want to make it a flash message and then display it elsewhere in the master template.

Happy to provide further information if required.

t2t

2

2 Answers

1
votes

You can create an eventListener on 'onAuthenticationFailure'. You will get the request and referer.

0
votes

In your case; you need to create custom Login page.

To do that;

1- Create your own SecurityController.php. Then copy 'loginAction' and 'renderLogin' method from the original SecurityController friendsofsymfony/user-bundle/SecurityController.php paste into it and add /login path to loginAction.

2- Create your own login.html.twig. Then copy content of login_content.html.twig from friendsofsymfony/user-bundle/Resources/Security/login_content.html.twig paste into your own.

3- Change return of renderLogin to your own login.html.twig

After these steps you can modify whatever you want. If you want to different route after wrong credentials then check the $error variable and make redirection.