# Expiration de la session

Questions ou commentaires?

## But

Créer un délai d'inactivité qui avertit les utilisateurs lorsque leur session est sur le point d'expirer.

Ce plugiciel aidera les propriétaires d'actifs Web à configurer leurs actifs avec une fonction « Expiration de la session ». Celle-ci sera activée en deux circonstances : après une période de temps spécifique ou lors d'inactivité.

Par exemple, si l'utilisateur demeure trop longtemps sur la même page, la fonction sera activée. De même, si l’utilisateur demeure inactif, la fonction sera activée. Le fureteur affichera alors une boîte de dialogue proposant deux options à l'utilisateur ; s’il souhaite rester connecté il devra sélectionner « Continuer la session » et ce, dans un laps de temps précis et s’il souhaite mettre fin à sa session, il n’aura qu’à choisir « Mettre fin à la session ». Advenant que l'utilisateur tarde trop à faire son choix, ce sera le paramètre de déconnexion qui s’affichera.

Needs translation

## Use when

- A session timeout warning is required. This will alert the user before their session expires and give them a chance to extend the session.
- User activity on a web page should extend their session.

## Exemple pratique

Exemple en anglais

Exemple en français

Needs translation

## How to implement

1. Add a `class="wb-sessto"` element to the web page (only required once). You must set the `logouturl`, which controls where the user is redirected if their session expires:

       <span class="wb-sessto" data-wb-sessto='{"logouturl": "http://app.gc.ca/logout"}'></span>

2. Configure the plugin using the `data-wb-sessto` attribute of the element:

       <span class="wb-sessto" data-wb-sessto='{
       		"inactivity": 1200000,
       		"reactionTime": 30000,
       		"sessionalive": 1200000,
       		"logouturl": "./",
       		"refreshCallbackUrl": "./"
       		"refreshOnClick": true,
       		"refreshLimit": 200000}'></span>

## Configuration options

All configuration options of the plugin are controlled by the `data-wb-sessto` attribute or `window[ "wb-sessto" ]`. Any configuration parameter that accepts a time value, can optionally have the time unit specified (e.g. "100 ms").

Supported time units are:

- `ms`: millisecond (0.001 seconds)
- `cs`: centisecond (0.01 seconds)
- `ds`: decisecond (0.1 seconds)
- `s`: seconds (1 second)
- `das`: dekasecond (10 seconds)
- `hs`: hectosecond (100 seconds)
- `ks`: kilosecond (1,000 seconds)

Option | Description | How to configure | Values
--- | --- | --- | ---
`inactivity` | Sets the inactivity timeout. Once this expires, the plugin's modal dialog will appear and prompt the user to continue or end their session. | Provide a numeric value, optionally with a time unit appended. | None (default): Default inactivity period is 20 minutes. Numeric value: Treated as a millisecond value. String numeric value with time unit appended (e.g. "100 s"): Treated as a time value in the provided unit.
`reactionTime` | Sets the period of time the user has to perform an action once the modal dialog is displayed | Provide a numeric value, optionally with a time unit appended. | None (default): Default reaction time is 3 minutes. Numeric value: Treated as a millisecond value. String numeric value with time unit appended (e.g. "100 s"): Treated as a time value in the provided unit.
`sessionalive` | Sets the period of time before an ajax request is made to the server to determine if the session is still alive. A `refreshCallbackUrl` must be specified for this to work. | Provide a numeric value, optionally with a time unit appended. | None (default): Default session alive time is 20 minutes. Numeric value: Treated as a millisecond value. String numeric value with time unit appended (e.g. "100 s"): Treated as a time value in the provided unit.
`logouturl` | URL that users are sent to when their session has expired. | Provide a URL. | None (default): Default logout URL is "./" String URL: The URL to redirect to once the session has expired.
`refreshCallback` | The function used to check the response received from `refreshCallbackUrl`. This parameter cannot be specified on the `data-wb-sessto` attribute. | Provide a function. | None (default): The response is matched exactly to the literal string "true". Function: The function needs to accept a single string parameter, which will be the response body text. It must return true if the session is alive, or false otherwise.
`refreshCallbackUrl` | URL used to perform an ajax request to determine the validity of the session. See the `method` and `refreshCallback` parameters for more details. | Provide a URL. | None (default): No ajax request will be performed. String URL: An ajax request (POST) will be made to the URL.
`refreshOnClick` | Determines if clicking on the document should reset the inactivity timeout and perform an ajax request (if a `refreshCallbackUrl` has been specified). | Provide a boolean true/false value. | None (default): true (refresh on click is turned on) Boolean: true/false.
`refreshLimit` | Sets the amount of time that must pass before an ajax request can be made. | Provide a numeric value, optionally with a time unit appended. | None (default): Default refresh limit is 2 minutes. Numeric value: Treated as a millisecond value. String numeric value with time unit appended (e.g. "100 s"): Treated as a time value in the provided unit.
`method` | Sets the request method used for ajax requests. While all methods are accepted, the response must contain a message body therefore methods that preclude this are not recommended. Recommended: GET, POST. | Provide a string value. | None (default): The POST request method is used. String: Treated as the request method (HTTP verb). The method is used as entered.
`additionalData` | Additional data to send with the request. | Provide a string value, array, object or null. | None or null (default): No additional data is sent with the request. String: Treated as a query string of the form `key1=value1&key2=value2` and sent as-is. Array or object: Converted to query string form before being sent with the request.

## Events

Document the public events that can be used by implementers or developers.

Event | Trigger | What it does
--- | --- | ---
`wb-init.wb-sessto` | Triggered manually (e.g., `$( ".wb-sessto" ).trigger( "wb-init.wb-sessto" );`). | Initializes the plugin and starts the session and inactivity timeouts. Note: the session timeout plugin will be initialized automatically unless the .wb-sessto element is added after the page has already loaded.
`wb-ready.wb-sessto` (v4.0.5+) | Triggered automatically after the Session timeout plugin initializes. | Used to identify when and where the Session timeout plugin initializes (target of the event).
    $( document ).on( "wb-ready.wb-sessto", ".wb-sessto", function( event ) {
    });
    $elm.on( "wb-ready.wb-sessto", function( event ) {
    });
`inactivity.wb-sessto` | Triggered manually and by the plugin (e.g., `$( ".wb-sessto" ).trigger( "inactivity.wb-sessto" );`). | Causes the modal dialog to appear and prompt the user to continue or end their session. This event is triggered automatically when the `inactivity` timeout expires.
`keepalive.wb-sessto` | Triggered manually and by the plugin (e.g., `$( ".wb-sessto" ).trigger( "keepalive.wb-sessto" );`). | Causes an ajax request to be made (if a `refreshCallbackUrl` has been specified). This will alert the user that their session has expired if the `refreshCallbackUrl` response is not "true".
`reset.wb-sessto` | Triggered manually and by the plugin (e.g., `$( ".wb-sessto" ).trigger( "reset.wb-sessto" );`). | Restarts the `inactivity` and `keepalive` timeouts.
`wb-ready.wb` (v4.0.5+) | Triggered automatically when WET has finished loading and executing. | Used to identify when all WET plugins and polyfills have finished loading and executing.
    $( document ).on( "wb-ready.wb", function( event ) {
    });

Note: when manually triggering the `inactivity`, `keepalive` and `reset` events, you must pass the `data-wb-sessto` attribute as a second argument:

    // Get a reference to the session timeout element and its data-wb-sessto attribute
    	var $element = $( ".wb-sessto" ),
    		settings = $element.data( "wb-sessto" );

    	// Trigger the event on the element
    	$element.trigger( "reset.wb-sessto", settings );

## Source code

Session timeout source code on GitHub

Date de modification :
  2015-07-21