1

Symfony2 provides a very simple tool for user login. In practice, the framework do all the security controls for you. As shown in the official doc, a controller (SecurityController) can be used to load the login form page. Then, a route is associated to login check the input provided by the user through the login form. If the login is correct, the user is redirected to the home page (or another one); otherwise, the user must re-enter username and password.

Since I need to load in the session some user preference from a database, I want to know if there is a way to execute such a function once the login check ascertained the correctness of the user login. Any idea?

1 Answer 1

3

You have to write your own AuthenticationHandler which will implement two interfaces below:

class AuthenticationHandler implements AuthenticationSuccessHandlerInterface

In that handler you should define method onAuthenticationSuccess()

Inside this method you can do whatever you need.

Don't forget also to set your listener in security.yml

firewalls:
    main:
        ....
        your_form_login:
            ...
            success_handler: your.authentication_handler

Check also this useful doc

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I found this nice example. Thanks...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.