AC-471 Added back client session timeout. Fixed Rest service library to bubble up expired session and invalid token errors via promise object, enabling correct error handling. Now tracking last URL in session cookie and returning user to last URL after successful login.

This commit is contained in:
Chris Houseknecht
2013-11-05 17:36:19 +00:00
parent 826745d2b5
commit 51aae28a1e
11 changed files with 238 additions and 93 deletions

View File

@@ -0,0 +1,55 @@
/**************************************************
* Copyright (c) 2013 AnsibleWorks, Inc.
*
* Timer.js
*
* Use to track user idle time and expire session. Timeout
* duration set in config.js
*
*/
angular.module('TimerService', ['ngCookies', 'Utilities'])
.factory('Timer', ['$rootScope', '$cookieStore', '$location', 'GetBasePath', 'Empty',
function($rootScope, $cookieStore, $location, GetBasePath, Empty) {
return {
sessionTime: null,
timeout: null,
getSessionTime: function() {
return (this.sessionTime) ? this.sessionTime : $cookieStore.get('sessionTime');
},
isExpired: function() {
var stime = this.getSessionTime();
var now = new Date().getTime();
if ((stime - now) <= 0) {
//expired
return true;
}
else {
// not expired. move timer forward.
this.moveForward();
return false;
}
},
expireSession: function() {
this.sessionTime = 0;
$rootScope.sessionExpired = true;
$cookieStore.put('sessionExpired', true);
},
moveForward: function() {
var t = new Date().getTime() + ($AnsibleConfig.session_timeout * 1000);
this.sessionTime = t;
$cookieStore.put('sessionTime', t);
$rootScope.sessionExpired = false;
$cookieStore.put('sessionExpired', false);
},
init: function() {
this.moveForward();
return this;
}
}
}]);