Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to implement it with a kernel listener, this is the way I solve it:</p> <p><strong>Listener</strong> <em>src/Comakai/MyBundle/Handler/SessionIdleHandler.php</em> <pre><code>namespace Comakai\MyBundle\Handler; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; class SessionIdleHandler { protected $session; protected $securityToken; protected $router; protected $maxIdleTime; public function __construct(SessionInterface $session, TokenStorageInterface $securityToken, RouterInterface $router, $maxIdleTime = 0) { $this-&gt;session = $session; $this-&gt;securityToken = $securityToken; $this-&gt;router = $router; $this-&gt;maxIdleTime = $maxIdleTime; } public function onKernelRequest(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST != $event-&gt;getRequestType()) { return; } if ($this-&gt;maxIdleTime &gt; 0) { $this-&gt;session-&gt;start(); $lapse = time() - $this-&gt;session-&gt;getMetadataBag()-&gt;getLastUsed(); if ($lapse &gt; $this-&gt;maxIdleTime) { $this-&gt;securityToken-&gt;setToken(null); $this-&gt;session-&gt;getFlashBag()-&gt;set('info', 'You have been logged out due to inactivity.'); // Change the route if you are not using FOSUserBundle. $event-&gt;setResponse(new RedirectResponse($this-&gt;router-&gt;generate('fos_user_security_login'))); } } } } </code></pre> <p><strong>Config</strong> <em>src/Comakai/MyBundle/Resources/config/services.yml (Comakai/MyBundle/DependencyInjection/MyBundleExtension.php)</em></p> <pre><code>services: my.handler.session_idle: class: Comakai\MyBundle\Handler\SessionIdleHandler arguments: ["@session", "@security.context", "@router", %session_max_idle_time%] tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } </code></pre> <p>Now you can set the <code>session_max_idle_time</code> in <strong>parameters.yml</strong> to 30 * 60 = <strong>1800</strong> seconds (or just hardcode the value wherever you want):</p> <p><strong>Parameters</strong> <em>app/config/parameters.yml</em></p> <pre><code>parameters: ... session_max_idle_time: 1800 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload