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?
You have to write your own
AuthenticationHandlerwhich will implement two interfaces below: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.ymlCheck also this useful doc