注销处理程序Silex

时间:2016-06-02 14:50:39

标签: security service logout silex provider

我想在注销后更改USER的状态。但我不知道如何制作它。

$app->register(new Silex\Provider\SecurityServiceProvider());
$app['security.firewalls'] = array(
        'chat' => array(
            'pattern'=>'/chat',
            'anonymous'=>false,
            //login_path: before authorisation  Check_path: path to check the date of the user
            'form'=>array('login_path'=>'/login','check_path' => '/chat/login_check'),
            //should realizise the logout
            'logout'=>array('logout_path'=>'/chat/logout','target_url'=>'/logout'),
            'users'=> $app->share(function() use ($app){
                return new \resources\controller\UserProvider($app['db']);
            })
        )
);

似乎没有会话了。我已经和

'invalidate_session'=>false 

'invalidate_session'=>true 

选项。它不工作。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您可以添加注销处理程序

$app->extend('security.firewall', function($firewall, $app) {
    static $initialized = false;
    if ($initialized) return $firewall;
    $initialized = true;

    // logout handlers
    $app['security.authentication_listener.administration.logout']->addHandler(
        new \My\Logout\LogoutHandler()
    );

    return $firewall;
});

LogoutHandler应该实现LogoutHandlerInterface

class LogoutHandler implements LogoutHandlerInterface
{
    public function logout(Request $request, Response $response, TokenInterface $token)
    {
        $user = $token->getUser();
    }
}