You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspired by [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap)
3
+
4
+
You can easily upgrade [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap) to bootstrap-session-timeout. 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
+
## Description
7
+
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, a keep-alive URL is requested through AJAX (optional) to keep the session alive. If no option is selected after another set amount of idle time, the page is automatically redirected to a timeout URL.
8
+
9
+
Idle time is defined as no mouse, keyboard or touch event activity registered by the browser. As long as the user is active, the keep-alive URL also keeps getting pinged and the session stays alive. Optionally, you can also use this plugin as a simple lock mechanism on its own, if you have no need to keep the server-side session alive.
10
+
11
+
12
+
## Getting Started
13
+
14
+
1. Include `jQuery`
15
+
2. Include `bootstrap.js` and `bootstrap.css`<br>(to support the modal dialog, unless you plan on using your own callback)
16
+
3. Include `bootstrap-session-timeout.js` or `bootstrap-session-timeout.min.js`<br>(from the /dist folder)
17
+
4. Call `$.sessionTimeout();` after document ready
18
+
19
+
20
+
21
+
## Documentation
22
+
### Options
23
+
**message**<br>
24
+
25
+
Type: `String`
26
+
27
+
Default: `'Your session is about to expire.'`
28
+
29
+
Text shown to user in dialog after warning period.
30
+
31
+
**keepAliveUrl**
32
+
33
+
Type: `String`
34
+
35
+
Default: `'/keep-alive'`
36
+
37
+
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.
38
+
39
+
**keepAlive**
40
+
41
+
Type: `Boolean`
42
+
43
+
Default: `true`
44
+
45
+
If `true`, pings the **keepAliveUrl** if the user clicks "Stay Connected" on the Bootstrap warning dialog. If you have no server-side session timeout to worry about, feel free to set this one to `false` to prevent unnecessary network activity.
46
+
47
+
**keepAliveInterval**
48
+
49
+
Type: `Integer`
50
+
51
+
Default: `5000` (5 seconds)
52
+
53
+
Minimum time in milliseconds between two keep-alive pings.
54
+
55
+
**redirUrl**
56
+
57
+
Type: `String`
58
+
59
+
Default: `'/timed-out'`
60
+
61
+
URL to take browser to if no action is take after warning period.
62
+
63
+
**logoutUrl**
64
+
65
+
Type: `String`
66
+
67
+
Default: `'/log-out'`
68
+
69
+
URL to take browser to if user clicks "Logout" on the Bootstrap warning dialog.
70
+
71
+
**warnAfter**
72
+
73
+
Type: `Integer`
74
+
75
+
Default: `900000` (15 minutes)
76
+
77
+
Time in milliseconds after page is opened until warning dialog is opened.
78
+
79
+
**redirAfter**
80
+
81
+
Type: `Integer`
82
+
83
+
Default: `1200000` (20 minutes)
84
+
85
+
Time in milliseconds after page is opened until browser is redirected to redirUrl.
86
+
87
+
**ignoreUserActivity**
88
+
89
+
Type: `Boolean`
90
+
91
+
Default: `false`
92
+
93
+
If `true`, this will launch the Bootstrap warning dialog / redirect (or callback functions) in a set amounts of time regardless of user activity.
94
+
95
+
**onWarn**
96
+
97
+
Type: `Function` or `Boolean`
98
+
99
+
Default: `false`
100
+
101
+
Custom callback you can use instead of showing the Bootstrap warning dialog. Note that if you need the keepAlive option, you will need to include it yourself in the callback function. See Examples below.
102
+
103
+
Redirect action will still occur unless you also use add the onRedir callback.
104
+
105
+
**onRedir**
106
+
107
+
Type: `Function` or `Boolean`
108
+
109
+
Default: false
110
+
111
+
Custom callback you can use instead of redirectiong the user to **redirUrl**.
112
+
113
+
## Examples
114
+
115
+
**Basic Usage**
116
+
117
+
Shows the warning dialog after one minute. The dialog is visible for another minute. If user takes no action, browser is redirected to `redirUrl`.
118
+
119
+
```js
120
+
$.sessionTimeout({
121
+
message:'Your session will be locked in one minute.',
122
+
keepAliveUrl:'keep-alive.html',
123
+
logoutUrl:'login.html',
124
+
redirUrl:'locked.html',
125
+
warnAfter:60000,
126
+
redirAfter:120000
127
+
});
128
+
```
129
+
130
+
**With onWorn Callback**
131
+
132
+
Shows the "Warning!" alert after one minute. If user takes no action, after one more minute the browser is redirected to `redirUrl`.
133
+
134
+
```js
135
+
$.sessionTimeout({
136
+
redirUrl:'locked.html',
137
+
warnAfter:60000,
138
+
redirAfter:120000,
139
+
onWarn:function{
140
+
alert('Warning!');
141
+
}
142
+
});
143
+
```
144
+
145
+
**With both onWorn and onRedir Callback**
146
+
147
+
Console logs the "Your session will soon expire!" text after one minute. If user takes no action, after two more minutes the "Your session has expired!" alert gets shown. No redirection occurs.
148
+
149
+
```js
150
+
$.sessionTimeout({
151
+
warnAfter:60000,
152
+
redirAfter:180000,
153
+
onWarn:function{
154
+
console.log('Your session will soon expire!');
155
+
},
156
+
onRedir:function{
157
+
alert('Your session has expired!');
158
+
}
159
+
});
160
+
```
161
+
162
+
## Contributing
163
+
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/).
164
+
165
+
## Release History
166
+
* 2012-09-10 v1.0.0 Initial release.
167
+
168
+
## License
169
+
Copyright (c) 2014 [Orange Hill](http://www.orangehilldev.com). Licensed under the MIT license.
0 commit comments