Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 lars 1
# bootstrap-session-timeout
2
Inspired by [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap)
3
 
4
There have been a number of major upgrades. For example, as long as the user is doing something on the page, he will never get a timeout. The original plugin launched a timeout warning dialog in a fixed amount of time regardless of user activity. See description and documentation for more information.
5
 
6
You can easily upgrade from jquery-sessionTimeout-bootstrap to bootstrap-session-timeout, since the basic options have been inherited from jquery-sessionTimeout-bootstrap and have not been renamed.
7
 
8
## Description
9
After a set amount of idle time, a Bootstrap warning dialog is shown to the user with the option to either log out, or stay connected. If "Logout" button is selected, the page is redirected to a logout URL. If "Stay Connected" is selected the dialog closes and the session is kept alive. If no option is selected after another set amount of idle time, the page is automatically redirected to a set timeout URL.
10
 
11
Idle time is defined as no mouse, keyboard or touch event activity registered by the browser.
12
 
13
As long as the user is active, the (optional) keep-alive URL keeps getting pinged and the session stays alive. If you have no need to keep the server-side session alive via the keep-alive URL, you can also use this plugin as a simple lock mechanism that redirects to your lock-session or log-out URL after a set amount of idle time.
14
 
15
 
16
## Getting Started
17
 
18
1. Download or git clone.
19
2. Run `bower install` to install dependencies or if you prefer to do it manually: include jQuery, Bootstrap JS and CSS (required if you want to use Bootstrap modal window).
20
3. Include `bootstrap-session-timeout.js` or the minified version `bootstrap-session-timeout.min.js`
21
4. Call `$.sessionTimeout();` on document ready. See available options below or take a look at the examples.
22
 
23
 
24
 
25
## Documentation
26
### Options
27
**title**<br>
28
 
29
Type: `String`
30
 
31
Default: `'Your session is about to expire!'`
32
 
33
This is the text shown to user via Bootstrap warning dialog after warning period. (modal title)
34
 
35
**message**<br>
36
 
37
Type: `String`
38
 
39
Default: `'Your session is about to expire.'`
40
 
41
This is the text shown to user via Bootstrap warning dialog after warning period.
42
 
43
**logoutButton**<br>
44
 
45
Type: `String`
46
 
47
Default: `'Logout'`
48
 
49
This is the text shown to user via Bootstrap warning dialog after warning period in the logout button.
50
 
51
**keepAliveButton**<br>
52
 
53
Type: `String`
54
 
55
Default: `'Stay Connected'`
56
 
57
This is the text shown to user via Bootstrap warning dialog after warning period in the Keep Alive button.
58
 
59
**keepAliveUrl**
60
 
61
Type: `String`
62
 
63
Default: `'/keep-alive'`
64
 
65
URL to ping via AJAX POST to keep the session alive. This resource should do something innocuous that would keep the session alive, which will depend on your server-side platform.
66
 
67
**keepAlive**
68
 
69
Type: `Boolean`
70
 
71
Default: `true`
72
 
73
If `true`, the plugin keeps pinging the `keepAliveUrl` for as long as the user is active. The time between two pings is set by the `keepAliveInterval` option. If you have no server-side session timeout to worry about, feel free to set this one to `false` to prevent unnecessary network activity.
74
 
75
**keepAliveInterval**
76
 
77
Type: `Integer`
78
 
79
Default: `5000` (5 seconds)
80
 
81
Time in milliseconds between two keep-alive pings.
82
 
83
**ajaxType**
84
 
85
Type: `String`
86
 
87
Default: `'POST'`
88
 
89
If you need to specify the ajax method
90
 
91
**ajaxData**
92
 
93
Type: `String`
94
 
95
Default: `''`
96
 
97
If you need to send some data via AJAX POST to your `keepAliveUrl`, you can use this option.
98
 
99
**redirUrl**
100
 
101
Type: `String`
102
 
103
Default: `'/timed-out'`
104
 
105
URL to take browser to if no action is take after the warning.
106
 
107
**logoutUrl**
108
 
109
Type: `String`
110
 
111
Default: `'/log-out'`
112
 
113
URL to take browser to if user clicks "Logout" on the Bootstrap warning dialog.
114
 
115
**warnAfter**
116
 
117
Type: `Integer`
118
 
119
Default: `900000` (15 minutes)
120
 
121
Time in milliseconds after page is opened until warning dialog is opened.
122
 
123
**redirAfter**
124
 
125
Type: `Integer`
126
 
127
Default: `1200000` (20 minutes)
128
 
129
Time in milliseconds after page is opened until browser is redirected to `redirUrl`.
130
 
131
**ignoreUserActivity**
132
 
133
Type: `Boolean`
134
 
135
Default: `false`
136
 
137
If `true`, this will launch the Bootstrap warning dialog / redirect (or callback functions) in a set amounts of time regardless of user activity. This in turn makes the plugin act much like the [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap) plugin.
138
 
139
**countdownSmart**
140
 
141
Type: `Boolean`
142
 
143
Default: `false`
144
 
145
If `true`, displays minutes as well as seconds in the countdown timer (e.g. "3m 14s").
146
Displays only seconds when timer is under one minute (e.g. "42s").
147
 
148
**countdownMessage**
149
 
150
Type: `String` or `Boolean`
151
 
152
Default: `false`
153
 
154
If you want a custom sentence to appear in the warning dialog with a timer showing the seconds remaining, use this option. Example: `countdownMessage: 'Redirecting in {timer}.'` Place the `{timer}` string where you want the numeric countdown to appear. Another example: `countdownMessage: '{timer} remaining.'`. Can be combined with countdownBar option or used independently.
155
 
156
**countdownBar**
157
 
158
Type: `Boolean`
159
 
160
Default: `false`
161
 
162
If `true`, ads a countdown bar (uses Bootstrap progress bar) to the warning dialog. Can be combined with countdownMessage option or used independently.
163
 
164
**onStart**
165
 
166
Type: `Function` or `Boolean`
167
 
168
Default: `false`
169
 
170
Optional callback fired when first calling the plugin and every time user refreshes the session (on any mouse, keyboard or touch action). Takes options object as the only argument.
171
 
172
 
173
**onWarn**
174
 
175
Type: `Function` or `Boolean`
176
 
177
Default: `false`
178
 
179
Custom callback you can use instead of showing the Bootstrap warning dialog. Takes options object as the only argument.
180
 
181
Redirect action will still occur unless you also add the `onRedir` callback.
182
 
183
**onRedir**
184
 
185
Type: `Function` or `Boolean`
186
 
187
Default: `false`
188
 
189
Custom callback you can use instead of redirecting the user to `redirUrl`. Takes options object as the only argument.
190
 
191
## Examples
192
 
193
You can play around with the examples in the `/examples` directory.
194
 
195
 
196
**Basic Usage**
197
 
198
Shows the warning dialog after one minute. The dialog is visible for another minute. If user takes no action (interacts with the page in any way), browser is redirected to `redirUrl`. On any user action (mouse, keyboard or touch) the timeout timer is reset. Of course, you will still need to close the dialog.
199
 
200
```js
201
$.sessionTimeout({
202
	message: 'Your session will be locked in one minute.',
203
	keepAliveUrl: 'keep-alive.html',
204
	logoutUrl: 'login.html',
205
	redirUrl: 'locked.html',
206
	warnAfter: 60000,
207
	redirAfter: 120000
208
});
209
```
210
 
211
**With onWarn Callback**
212
 
213
Shows the "Warning!" alert after one minute. If user takes no action (interacts with the page in any way), after one more minute the browser is redirected to `redirUrl`. On any user action (mouse, keyboard or touch) the timeout timer is reset.
214
 
215
```js
216
$.sessionTimeout({
217
	redirUrl: 'locked.html',
218
	warnAfter: 60000,
219
	redirAfter: 120000,
220
	onWarn: function () {
221
		alert('Warning!');
222
	}
223
});
224
```
225
 
226
**With both onWarn and onRedir Callback**
227
 
228
Console logs the "Your session will soon expire!" text after one minute. If user takes no action (interacts with the page in any way), after two more minutes the "Your session has expired!" alert gets shown. No redirection occurs. On any user action (mouse, keyboard or touch) the timeout timer is reset.
229
 
230
```js
231
$.sessionTimeout({
232
	warnAfter: 60000,
233
	redirAfter: 180000,
234
	onWarn: function () {
235
		console.log('Your session will soon expire!');
236
	},
237
	onRedir: function () {
238
		alert('Your session has expired!');
239
	}
240
});
241
```
242
 
243
**With countdown message and bar displayed in warning dialog**
244
 
245
Same as basic usage except you'll also see the countdown message and countdown bar in the warning dialog. Uses Bootstrap progress bar. In countdownMessage place the `{timer}` string where you want the numeric countdown (seconds) to appear.
246
 
247
```js
248
$.sessionTimeout({
249
    keepAliveUrl: 'keep-alive.html',
250
    logoutUrl: 'login.html',
251
    redirUrl: 'locked.html',
252
    warnAfter: 60000,
253
	redirAfter: 120000,
254
    countdownMessage: 'Redirecting in {timer} seconds.',
255
    countdownBar: true
256
});
257
```
258
 
259
## Contributing
260
In lieu of a formal styleguide, take care to maintain the existing coding style. Add comments for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
261
 
262
## Release History
263
 * **1.0.3** `2015-07-17`
264
	 * Fixes various reported bugs
265
 * **1.0.2** `2015-02-10`
266
	 * Added optional onStart callback.
267
	 * All custom callbacks nowreceive options object as argument.
268
	 * Added optional countdown message. Added optional countdown bar.
269
 * **1.0.1** `2014-01-23`
270
	 * Added an option to send data to the keep-alive URL.
271
 * **1.0.0** `2014-01-22`
272
	 * Initial release.
273
 
274
## License
275
Copyright (c) 2014 [Orange Hill](http://www.orangehilldev.com). Licensed under the MIT license.