覆盖login_check操作 . 我需要添加一些额外的功能 . 当用户提交表单时,我需要检查他的角色和用户实体中的一些其他字段 .

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Component\HttpFoundation\RedirectResponse;

class SecurityListener
{
    private $securityContext;
    private $router;
    private $session;

    public function __construct($userManager, $securityContext, $session, $router)
    {

        $this->securityContext = $securityContext;
        $this->router = $router;
        $this->session = $session;
    }

    public static function getSubscribedEvents()
    {
        return array(
            SecurityEvents::INTERACTIVE_LOGIN => 'onSecurityInteractiveLogin',
        );
    }

    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
        $user = $event->getAuthenticationToken()->getUser();
        $this->securityContext->getToken()->setAuthenticated(false);
        $this->securityContext->setToken(NULL);

        return new RedirectResponse('http://stackoverflow.com');
    }

我正在使用活动 . 我创建了自定义事件监听器 . 并覆盖onSecurityInteractiveLogin(类LastLoginListener实现EventSubscriberInterface) .

  • 重定向不起作用 .

  • 如何注销用户?我的方法是否正确?

  • 2个事件被解雇:1)我的2)默认,为什么?

  • 当我删除令牌第二个默认事件时,在登录表单上重定向我,但上次登录日期写入数据库 .

有谁能够帮我?