Symfony,强制注销控制器

时间:2018-10-26 09:43:24

标签: symfony symfony-security

我正在使用Symfony 3.4,我想在控制器操作结束时注销用户。

这是动作

public function changeUserEmail() {
     /* change the user email */
     /* perform the logout */
     /* choose the route to redirect to */
     return $this->redirectToRoute(/* some route choosen above */);
}

有没有一种方法可以实现/* perform the logout */的Symfony方法?我没有在文档中找到任何内容。 我确实想在控制器中注销(不想重定向到注销路径),并且想要选择要在控制器中重定向的路由。

非常感谢。

版本或Symfony为3.4

1 个答案:

答案 0 :(得分:2)

这是答案

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

// ...

public function changeUserEmail(TokenStorageInterface $tokenStorage) {
     /* change the user email */
     $tokenStorage->setToken();
     /* choose the route to redirect to */
     return $this->redirectToRoute(/* some route choosen above */);
}

不需要使所有会话无效,例如如果已定义多个防火墙。

相关问题