FOSUser捆绑包-禁止禁用的用户登录 [英] FOSUser Bundle - Prevent Disabled users from logging in
本文介绍了FOSUser捆绑包-禁止禁用的用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个loginsuccesshandler.php,正在检查用户是否启用了这样的功能!
I have created a loginsuccesshandler.php and am checking if the user is !enabled like this
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$user = $token->getUser();
if(!$user->isEnabled())
{//do not pass go
$request->getSession()->invalidate();
$this->security->setToken(null);
//$token->setToken(null);
return new RedirectResponse($this->router->generate('account_disabled'));
}
此行
$request->getSession()->invalidate();
正在导致以下错误:
Warning: SessionHandler::write(): Parent session handler is not open in /var/www...
但是我无法删除它,因为如果用户单击记住我"复选框,他们仍将登录.
But I cant remove it because if the user clicks the remember me checkbox, they will still be logged in.
我退出FOS时遇到了同样的问题,但是我将其添加到了配置中
I had the same problem with FOS logging out, but I added this to the config
logout:
invalidate_session: false
推荐答案
您做错了. Symfony已经内置了实现该功能的机制:
You're doing it wrong. Symfony has already built-in mechanism to achieve that:
- 为您实施
AdvancedUserInterface
User
类. - ...就是这样.有关更多信息,请阅读 http://symfony.com/doc /current/cookbook/security/entity_provider.html#forbid-inactive-users
- Implement
AdvancedUserInterface
for yourUser
class. - ...and that's it. For more, read http://symfony.com/doc/current/cookbook/security/entity_provider.html#forbid-inactive-users
这篇关于FOSUser捆绑包-禁止禁用的用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文