Do something just after symfony2 login success and before redirect?

前端 未结 1 2018

I\'m searching for a while now, for any info, on how to do something after authentication success in symfony2. I want to rehash user password to use bcrypt just after succes

相关标签:
1条回答
  • 2020-12-16 18:37

    You can specify a login success handler to be executed on successful login.

    For example, your security.yml

    firewalls:
        main:
            pattern: ^/
            form_login:
                success_handler: my.security.login_handler
    

    Now create the class which implements Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface and on successful login, you can do whatever you need and handle the redirect as you see fit.

    /**
     * 
     */
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        // handle it and return a response
    }
    

    Then create a service with that name in your services.xml for your bundle, or in your config.yml using the newly created handler.

    I originally found out how to do this following this tutorial:

    http://www.reecefowell.com/2011/10/26/redirecting-on-loginlogout-in-symfony2-using-loginhandlers/

    0 讨论(0)
提交回复
热议问题