FOSUserBundle이 통합 된 Symfony 2.5 프로젝트가 있습니다. 나는 로그인 된 사용자가 자동으로 로그 아웃되어 로그인 페이지로 리다이렉트되도록 앱의 X 유휴 시간을 요구한다.Symfony 2.5 - 비활성 기간 후 자동 리디렉션
지금까지 나는 꽤 유사 여기 How to log users off automatically after a period of inactivity?
<?php
namespace MyProject\UserBundle\EventListener;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
class UserInactivityListener
{
protected $session;
protected $securityContext;
protected $router;
protected $maxIdleTime;
public function __construct(
SessionInterface $session,
SecurityContextInterface $securityContext,
RouterInterface $router,
$maxIdleTime = 0)
{
$this->session = $session;
$this->securityContext = $securityContext;
$this->router = $router;
$this->maxIdleTime = $maxIdleTime;
}
/**
* user will be logged out after 30 minutes of inactivity
*
* @param FilterControllerEvent $event
* @return type
*/
public function onKernelController(FilterControllerEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST != $event- >getRequestType()) {
return;
}
if ($this->maxIdleTime > 0) {
try {
$this->session->start();
$lapse = time() - $this->session->getMetadataBag()->getLastUsed();
$isFullyAuthenticated = $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY');
if (($lapse > $this->maxIdleTime) && $isFullyAuthenticated == true) {
$this->securityContext->setToken(null);
$url = $this->router->generate('fos_user_security_login');
$event->setController(function() use ($url) {
return new RedirectResponse($url);
});
}
} catch (\Exception $ex) {
return;
}
}
}
}
에 제안, 솔루션을 구현했습니다 문제입니다이 이벤트가 트리거되고 사용자가하려고 할 때 리디렉션은 일어날 것입니다 유휴 시간이 지난 후에 앱에 아무것도로드하지 마세요. 내가 원하는 것은 사용자가 어떤 상호 작용없이 앱을 자동으로 가입 페이지로 리디렉션하는 것입니다.
새로 고침 메타 태그 How to auto redirect a user in Symfony after a session time out?을 사용하라는 제안이 나왔지만 지금 새로 고침 이벤트를 발생시키는 또 다른 좋은 방법이 있는지 궁금해하고 있었습니까?
감사합니다. @nurikable. 솔루션이 작동합니다. –