Symfony注销处理程序,区分按钮命中和会话到期

时间:2017-04-27 10:12:53

标签: php symfony

我的自定义注销处理程序如下:

namespace AppBundle\EventListener;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Doctrine\ORM\EntityManager;
use AppBundle\Entity\User;

class LogoutListener implements LogoutHandlerInterface
{
protected $securityContext;
protected $entityManager;
protected $logger;

public function __construct(TokenStorage $securityContext, EntityManager $entityManager, $logger)
{
    $this->securityContext = $securityContext;
    $this->entityManager = $entityManager;
    $this->logger = $logger;
}

public function logout(Request $Request, Response $Response, TokenInterface $Token)
{
    $em = $this->entityManager;
    $user = $this->securityContext->getToken()->getUser();
    $em->getConnection()->executeUpdate("UPDATE subjects SET edited_by = NULL
                  WHERE edited_by=" . $user->getId());

    $this->logger->makelog(1, 'Выход из системы');
}

在这里,我登录所有注销操作的文件。现在我需要区分按钮命中时的用户注销和会话到期。任何想法如何做到这一点?我应该实施什么服务。现在,在会话到期时注销只需在config.yml

中处理
session:
    save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
    cookie_lifetime: 3600
    gc_maxlifetime: 3600

0 个答案:

没有答案