-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery-sessionTimeoutManager.js
More file actions
125 lines (96 loc) · 3.61 KB
/
jquery-sessionTimeoutManager.js
File metadata and controls
125 lines (96 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// JQuery Session Timeout Manager //
// Description: Shows a dialog using JQuery Confirm to alert the user before their session //
// times out. //
// //
// Created By: (C) Studio7 Web Development 2018 //
///////////////////////////////////////////////////////////////////////////////////////////////
if (typeof jQuery === 'undefined') {
throw new Error('jquery-sessionTimeoutManager requires jQuery');
}
if (typeof jconfirm === 'undefined') {
throw new ReferenceError('jquery-sessionTimeoutManager requires jConfirm. See Documentation.');
}
var tmrSTM;
var timeoutInterval;
var thisInterval;
var opts;
(function ($) {
"use strict";
$.fn.sessionTimeoutManager = function (options) {
opts = $.extend({}, $.fn.sessionTimeoutManager.defaults, options);
this.initialize = function () {
console.info("Plugin Initialised");
console.info("'" + opts.confirmColor + "'");
console.log(opts.redirectToURL);
timeoutInterval = Math.floor(opts.sessionActualTimeout - opts.warnUserBeforeDuration);
thisInterval = Math.floor(timeoutInterval / 1000 / 60) + "Minute(s)";
console.log("opts.elementToHook: " + opts.elementToHook);
if (opts.elementToHook === document) {
document.addEventListener("mousemove", this.resetTimer());
} else {
document.getElementById(opts.elementToHook).addEventListener("mousemove", this.resetTimer());
}
this.startTimer();
return this;
};
this.startTimer = function () {
tmrSTM = setTimeout(function () {
//Show user a dialog using the jconfirm plugin if option->warnUserWithDialog is true
if (opts.warnUserWithDialog) {
$.alert({
theme: 'material',
icon: opts.confirmIcon,
title: opts.confirmTitle,
content: opts.confirmText,
type: opts.confirmColor,
columnClass: 'col-md-6 col-md-offset-3',
autoClose: "cancel|60000",
buttons: {
confirm: {
text: opts.confirmButtonText,
action: opts.confirmAction
},
cancel: {
text: opts.cancelButtonText,
action: opts.cancelAction
}
}
});
} else {
document.location.href = opts.redirectToURL;
}
}, timeoutInterval);
//console.log("Timer Started");
};
this.stopTimer = function () {
clearTimeout(tmrSTM);
console.log("Timeout Stopped");
};
this.resetTimer = function () {
clearTimeout(tmrSTM);
this.startTimer();
console.log("Timeout Reset");
};
return this.initialize();
};
// Plugin defaults
$.fn.sessionTimeoutManager.defaults = {
sessionActualTimeout: 1500000,
warnUserWithDialog: true,
redirectToURL: document.location.href,
warnUserBeforeDuration: 650000,
elementToHook: document,
confirmTitle: ' Session Timeout Warning.',
confirmIcon: 'fas fa-exclamation-circle',
confirmColor: 'red',
confirmText: 'To keep your data safe your session will timeout in 60 seconds<br/>We take your security very seriously and as a result have implemented and inactivity timeout.<br></br> Click "Stay Signed In" to keep your session active.<br/><br/>Do you wish to stay signed in? When this dialog auto closes you will be signed out.',
confirmButtonText: '<i class="fas fa-times-circle"></i> Stay Signed In',
cancelButtonText: '<i class="fas fa-times-circle"></i> Log Out',
confirmAction: function () {
this.resetTimer();
},
cancelAction: function () {
document.location.href = opts.redirectToURL;
}
};
})(jQuery, window);