mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 21:18:26 -04:00
Separate logout by user or inactivity
This commit is contained in:
@@ -15,17 +15,21 @@ window.GOVUK.Modules.TimeoutPopup = window.GOVUK.Modules.TimeoutPopup || {};
|
|||||||
var seconds = Math.floor((difference % (1000 * 60)) / 1000);
|
var seconds = Math.floor((difference % (1000 * 60)) / 1000);
|
||||||
document.getElementById("timeLeft").innerHTML = + minutes + "m " + seconds + "s";
|
document.getElementById("timeLeft").innerHTML = + minutes + "m " + seconds + "s";
|
||||||
showTimer();
|
showTimer();
|
||||||
document.getElementById("logOutTimer").addEventListener("click", logoutUser);
|
document.getElementById("logOutTimer").addEventListener("click", signoutUser);
|
||||||
document.getElementById("extendSessionTimer").addEventListener("click", extendSession);
|
document.getElementById("extendSessionTimer").addEventListener("click", extendSession);
|
||||||
if (difference < 0) {
|
if (difference < 0) {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
intervalId = null;
|
intervalId = null;
|
||||||
closeTimer();
|
closeTimer();
|
||||||
logoutUser();
|
expireUserSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logoutUser() {
|
function expireUserSession() {
|
||||||
|
window.location.href = '/sign-out' + '?next=' + window.location.pathname;
|
||||||
|
}
|
||||||
|
|
||||||
|
function signoutUser() {
|
||||||
window.location.href = '/sign-out';
|
window.location.href = '/sign-out';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +55,8 @@ window.GOVUK.Modules.TimeoutPopup = window.GOVUK.Modules.TimeoutPopup || {};
|
|||||||
}
|
}
|
||||||
|
|
||||||
global.GOVUK.Modules.TimeoutPopup.checkTimer = checkTimer;
|
global.GOVUK.Modules.TimeoutPopup.checkTimer = checkTimer;
|
||||||
global.GOVUK.Modules.TimeoutPopup.logoutUser = logoutUser;
|
global.GOVUK.Modules.TimeoutPopup.expireUserSession = expireUserSession;
|
||||||
|
global.GOVUK.Modules.TimeoutPopup.signoutUser = signoutUser;
|
||||||
global.GOVUK.Modules.TimeoutPopup.extendSession = extendSession;
|
global.GOVUK.Modules.TimeoutPopup.extendSession = extendSession;
|
||||||
global.GOVUK.Modules.TimeoutPopup.showTimer = showTimer;
|
global.GOVUK.Modules.TimeoutPopup.showTimer = showTimer;
|
||||||
global.GOVUK.Modules.TimeoutPopup.closeTimer = closeTimer;
|
global.GOVUK.Modules.TimeoutPopup.closeTimer = closeTimer;
|
||||||
|
|||||||
@@ -72,16 +72,26 @@ describe('The session timer ', () => {
|
|||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('logoutUser method logs the user out', () => {
|
test('signoutUser method logs the user out', () => {
|
||||||
const logoutUserMethod = window.GOVUK.Modules.TimeoutPopup.logoutUser;
|
const signoutUserMethod = window.GOVUK.Modules.TimeoutPopup.signoutUser;
|
||||||
|
|
||||||
expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out'));
|
expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out'));
|
||||||
|
|
||||||
logoutUserMethod();
|
signoutUserMethod();
|
||||||
|
|
||||||
expect(window.location.href).toEqual(expect.stringContaining('/sign-out'));
|
expect(window.location.href).toEqual(expect.stringContaining('/sign-out'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('expireUserSession method logs the user out with next query parameter', () => {
|
||||||
|
const expireUserSessionMethod = window.GOVUK.Modules.TimeoutPopup.expireUserSession;
|
||||||
|
|
||||||
|
expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out?next='));
|
||||||
|
|
||||||
|
expireUserSessionMethod();
|
||||||
|
|
||||||
|
expect(window.location.href).toEqual(expect.stringContaining('/sign-out?next='));
|
||||||
|
});
|
||||||
|
|
||||||
test('extendSession method reloads the page', () => {
|
test('extendSession method reloads the page', () => {
|
||||||
const windowReload = jest.spyOn(window.location, 'reload');
|
const windowReload = jest.spyOn(window.location, 'reload');
|
||||||
const extendSessionMethod = window.GOVUK.Modules.TimeoutPopup.extendSession;
|
const extendSessionMethod = window.GOVUK.Modules.TimeoutPopup.extendSession;
|
||||||
|
|||||||
Reference in New Issue
Block a user