mirror of
https://github.com/ansible/awx.git
synced 2026-05-21 07:47:44 -02:30
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:
55
awx/ui/static/lib/ansible/Timer.js
Normal file
55
awx/ui/static/lib/ansible/Timer.js
Normal 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;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
Reference in New Issue
Block a user