【发布时间】:2016-04-23 18:16:55
【问题描述】:
用户更改密码后(在恢复密码操作中),我需要使连接到该用户的所有会话无效(他可能在多个浏览器/设备上登录)。因此,在我用新密码将用户保存在数据库中之后,我需要关闭该用户在不同浏览器/设备中可能处于活动状态的所有会话。我试过这个:
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
也试过了:
$this->get('security.token_storage')->getToken()->setAuthenticated(false);
还有这个:
$this->get('security.token_storage')->setToken(null);
提前致谢!
我已将此添加到我的用户类中:
class User implements UserInterface, EquatableInterface, \Serializable{
// properties and other methods
public function isEqualTo(UserInterface $user){
if ($user->getPassword() !== $this->getPassword()){
return false;
}
if ($user->getEmail() !== $this->getEmail()){
return false;
}
if ($user->getRoles() !== $this->getRoles()){
return false;
}
return true;
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->email,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
}
【问题讨论】:
-
赞成,因为我不完全确定自己 - 阅读此内容是因为您想使连接到用户的所有会话无效(可以在多个浏览器/设备上登录)
-
是的,这就是我需要的。我将重写问题,以便更清楚。
标签: php symfony symfony-2.7