问题
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:
- Implement AdvancedUserInterface for your
User
class. - ...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