0

I am using FOSUSerBundle and have successfully overwritten Controllers, Forms and Views.

But I cannot find the correct place to set a flash message after unsuccessful login.

I already tried modifying the checkAction() in SecurityController.php, but it doesnt work.

Where is the correct place to set my flash message?

Thank you very much in advance!

Chris
  • 321
  • 1
  • 4
  • 14
  • 1
    Take a look [this](http://stackoverflow.com/a/8312188/453348) – tttony May 20 '14 at 19:17
  • thanks, tttony for the link. i suppose it does what i need, but after trying it out i came to the conclusion, that this approach is way to complicated for what i am looking for. – Chris May 25 '14 at 18:29

2 Answers2

1

I solved the problem pretty straight-forward:

1.) have overwritten the SecurityController and edited the loginAction

2.) hooked into the case where the login process returns an not empty $error

// in case the login process returns an error...
if ($error) {
    $error = $error->getMessage();

    // ... add the desired flash message to display
    $session->getFlashBag()->add('error', 'my error message here');
}
Chris
  • 321
  • 1
  • 4
  • 14
0

You dont need to overwrite the controller for it.

I overwrite the login.html.twig file and give the user the errors with the following line:

{% if error %}
        <div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
 {% endif %}
kristof
  • 129
  • 1
  • 14