[[appName]] [[appVersion]] @ [[_getEnv(environment)]]
@@ -174,7 +179,7 @@
1440) {
+ // more than a day
+
+ if (expiryMin < 1440) {
+ // expires today
+
+ // refresh now
+ console.log("Keep alive is " + keepAliveDays + " days and expiring today. Refreshing...");
+ this.refreshSession();
+
+ } else {
+ // check again in delayMin min
+ console.log("Keep alive is " + keepAliveDays + " days and expiring in the future. Delaying refresh for " + delayMin + "m...");
+ setTimeout(function () {
+ that.handleKeepAlive(Strolch.getUserConfig());
+ }, delayMin * 60 * 1000);
+ }
+ } else if (keepAliveMinutes < 15) {
+
+ console.error("The keepAliveMinutes is < 15minutes! Server is badly configured, ignoring!");
+
+ } else {
+ // less than a day
+
+ if (expiryMin > 15) {
+ // more than 15 min
+
+ // check again in delayMin
+ console.log("Keep alive is " + keepAliveMinutes + " minutes and expiring in " + expiryMin + "m. Delaying refresh for " + delayMin + "m...");
+ setTimeout(function () {
+ that.handleKeepAlive(Strolch.getUserConfig());
+ }, delayMin * 60 * 1000);
+
+ } else {
+ // less than 15 min
+
+ // refresh now
+ console.log("Keep alive is " + keepAliveMinutes + " minutes and expiring in " + expiryMin + "m. Refreshing...");
+ this.refreshSession();
+ }
+ }
},
sessionInvalid: function () {
console.log("Session invalid.");
@@ -326,6 +402,31 @@
this.$.ajaxAuth.generateRequest();
},
+ refreshSession: function () {
+ console.log("Refreshing session...");
+
+ if (Strolch.isEmptyString(Strolch.getAuthToken())) {
+ console.log("Can not refresh session as no auth token available!");
+ return;
+ }
+
+ this._ajaxResponse = function (e) {
+ console.log('Refreshed session which was about to expire...');
+ var data = e.detail.response;
+
+ var cookieExpiry = new Date(data.authorizationExpiration);
+ Strolch.setCookie("strolch.authorization", data.authToken, cookieExpiry);
+ Strolch.setCookie("strolch.authorization.expirationDate", data.authorizationExpiration, cookieExpiry);
+
+ Strolch.setAuthToken(data.authToken);
+ Strolch.setUserConfig(data);
+ };
+ this.dlgTitle = this.localize('sessionRefereshFailed');
+ this.$.ajaxAuth.url = this.basePath + 'rest/strolch/authentication/' + Strolch.getAuthToken();
+ this.$.ajaxAuth.method = 'PUT';
+ this.$.ajaxAuth.generateRequest();
+ },
+
_submitForm: function () {
if (!this.$.usernameInput.validate()) {
@@ -347,7 +448,8 @@
this.dlgTitle = this.localize('authenticationFailed');
this.$.ajaxAuth.body = {
username: this.username,
- password: btoa(unescape(encodeURIComponent(this.password)))
+ password: btoa(unescape(encodeURIComponent(this.password))),
+ keepAlive: this.keepAlive
};
this.$.ajaxAuth.url = this.basePath + 'rest/strolch/authentication';
this.$.ajaxAuth.method = 'POST';