Redirect Symfony2 LogoutSuccessHandler to original logout target

前端 未结 3 2029
攒了一身酷
攒了一身酷 2020-12-10 15:25

I need to modify my user object on logout. To do this, I have a security.yml that contains the following (amongst other things) -

#...
    logout:
        s         


        
3条回答
  •  再見小時候
    2020-12-10 15:58

    You could define your target as a parameter in your parameters.yml or config.yml:

    parameters:
        logout.target: /
    

    And then reference this value in your security.yml:

        logout:
            success_handler: my.logout_success_handler
            target: %logout.target%   
    

    And/or inject it into your logout handler:

        my.security.logout_success_handler:
            class: My\Security\LogoutSuccessHandler
            arguments: ["@security.context", "@doctrine.orm.default_entity_manager", %logout.target%]
    

    And return a RedirectResponse with this value:

    // Assign the 3. constructor parameter to the instance variable $logoutTarget
    
    public function onLogoutSuccess(Request $request)
    {
        // ...
    
        return new RedirectResponse($this->logoutTarget);
    }
    

提交回复
热议问题