FOSUser Bundle - Prevent Disabled users from logging in

て烟熏妆下的殇ゞ 提交于 2019-12-12 20:31:14

问题


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'));
            }

This line

 $request->getSession()->invalidate();

is causing the following error:

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.

I had the same problem with FOS logging out, but I added this to the config

    logout:
        invalidate_session: false

回答1:


You're doing it wrong. Symfony has already built-in mechanism to achieve that:

  1. Implement AdvancedUserInterface for your User class.
  2. ...and that's it. For more, read http://symfony.com/doc/current/cookbook/security/entity_provider.html#forbid-inactive-users


来源:https://stackoverflow.com/questions/21407071/fosuser-bundle-prevent-disabled-users-from-logging-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!