Commit 51f27ea5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

auto logout after session expired

parent b63a1057
......@@ -36,7 +36,7 @@ OverviewDialog.prototype.constructor = OverviewDialog;
/**
*
* @param {number} overviewImageId
* @param {number} [overviewImageId]
*/
OverviewDialog.prototype.showOverview = function (overviewImageId) {
var self = this;
......
......@@ -5,6 +5,7 @@ var Promise = require("bluebird");
/* exported logger */
var AbstractGuiElement = require('../AbstractGuiElement');
var ConfigurationType = require('../../ConfigurationType');
var GuiConnector = require('../../GuiConnector');
var OverviewDialog = require('../OverviewDialog');
var PanelControlElementType = require('../PanelControlElementType');
......@@ -31,6 +32,12 @@ function TopMenu(params) {
var self = this;
self._createGui();
self._cronFunction = function () {
return self.checkIfSessionIsGoingToExpire();
};
setInterval(self._cronFunction, 1000);
}
TopMenu.prototype = Object.create(AbstractGuiElement.prototype);
......@@ -270,6 +277,7 @@ TopMenu.prototype.destroy = function () {
if (self._overviewDialog !== undefined) {
self._overviewDialog.destroy();
}
clearInterval(self._cronFunction);
return Promise.resolve();
};
......@@ -286,4 +294,35 @@ TopMenu.prototype.toggleLegend = function () {
}
};
/**
*
* @returns {Promise}
*/
TopMenu.prototype.checkIfSessionIsGoingToExpire = function () {
var self = this;
var lastAccessTimestamp = self.getServerConnector().getSessionData().getLastRequestTimeStamp();
var sessionInactivityOption = self.getConfiguration().getOption(ConfigurationType.SESSION_LENGTH);
var sessionInactivityLength = parseInt(sessionInactivityOption.getValue());
var sessionExpireTimestamp = lastAccessTimestamp + sessionInactivityLength;
var currentTimestamp = Math.floor(Date.now() / 1000);
//if session is going to expire in 10 minutes show information
if (sessionExpireTimestamp - currentTimestamp < 10 * 60) {
self.showSessionExpire(sessionExpireTimestamp - currentTimestamp);
}
//if session expired 10 seconds ago force logout
if (sessionExpireTimestamp < currentTimestamp - 10) {
return self.getServerConnector().logout();
}
return Promise.resolve();
};
/**
*
*/
TopMenu.prototype.showSessionExpire = function (timeInSeconds) {
console.log("Session is going to expire in " + timeInSeconds + " seconds");
};
module.exports = TopMenu;
\ No newline at end of file
......@@ -298,7 +298,11 @@ Project.prototype.getTopOverviewImage = function () {
* @param {OverviewImage} topOverviewImage
*/
Project.prototype.setTopOverviewImage = function (topOverviewImage) {
this._topOverviewImage = topOverviewImage;
if (topOverviewImage === null) {
this._topOverviewImage = undefined;
} else {
this._topOverviewImage = topOverviewImage;
}
};
/**
......
......@@ -389,7 +389,9 @@ function create(params) {
topMenu = new TopMenu({
element: functions.getElementByClassName(element, "minerva-top-menu"),
customMap: customMap
customMap: customMap,
configuration: params.getConfiguration(),
project: params.getProject()
});
legend = new Legend({
......
......@@ -18,7 +18,8 @@ describe('TopMenu', function () {
new TopMenu({
element: testDiv,
customMap: map
customMap: map,
configuration: helper.getConfiguration()
});
assert.equal(logger.getWarnings().length, 0);
......@@ -30,7 +31,8 @@ describe('TopMenu', function () {
var topMenu = new TopMenu({
element: testDiv,
customMap: map
customMap: map,
configuration: helper.getConfiguration()
});
return topMenu.init();
......@@ -42,9 +44,14 @@ describe('TopMenu', function () {
var topMenu = new TopMenu({
element: testDiv,
customMap: map
customMap: map,
configuration: helper.getConfiguration()
});
var legend = new Legend({
element: document.createElement("div"), customMap: map,
configuration: helper.getConfiguration(),
project: map.getProject()
});
var legend = new Legend({element: document.createElement("div"), customMap: map});
topMenu.setLegend(legend);
return topMenu.init().then(function () {
$("input", testDiv).prop('checked', true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment