tui/session-bundle

Adds a session expiry listener

Installs: 817

Dependents: 0

Stars: 2

Watchers: 9

Forks: 3

Language: PHP

1.1.1 2013-04-20 10:12 UTC

README

Adds a listener that expires user sessions after a configurable period of inactivity.

Installation

Add this require reference to your composer.json:

php composer.phar require tui/session-bundle:~1.1

Add the Bundle to your app/AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        // …
        new Tui/SessionBundle/TuiSessionBundle(),
    }
    // …

You can configure the timeout in your app.yml file:

tui_session:
    session_timeout: 3600 # One hour

Redirecting on expiry

By default when the session expires, the listener will invalidate the session and throw a CredentialsExpired exception. Obviously it'd be much better to redirect the user to a "Login expired" page. There are two ways you can do that:

Redirect to a route

The listener can redirect to a given route when the session expires. This is super easy, but not very flexible. In your app.yml file:

tui_session:
    redirect_route: login_expired

Return a custom response

Alternatively you can create a custom response, register it as a service and configure it to be returned instead. Here's a trivial example that uses the built-in response class.

tui_session:
    expired_response: session_expired

services:
    session_expired:
        class: Symfony\Component\HttpFoundation\Response
        arguments:
            - 'Your login expired, sorry!'