Symfony,在控制器中强制注销
Symfony, force logout in a controller
我正在使用 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
答案在这里
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 */);
}
没有必要使所有会话失效,例如如果一个人定义了多个防火墙。
我正在使用 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
答案在这里
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 */);
}
没有必要使所有会话失效,例如如果一个人定义了多个防火墙。