mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Merge pull request #481 from jaredevantabor/logout-fixes
Wrapping timer init in promise
This commit is contained in:
commit
4de6fba70a
@ -947,7 +947,8 @@ var tower = angular.module('Tower', [
|
||||
control_socket.init();
|
||||
control_socket.on("limit_reached", function(data) {
|
||||
$log.debug(data.reason);
|
||||
Timer.expireSession('session_limit');
|
||||
$rootScope.sessionTimer.expireSession('session_limit');
|
||||
$location.url('/login');
|
||||
});
|
||||
}
|
||||
openSocket();
|
||||
@ -1023,9 +1024,11 @@ var tower = angular.module('Tower', [
|
||||
$rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser');
|
||||
// when the user refreshes we want to open the socket, except if the user is on the login page, which should happen after the user logs in (see the AuthService module for that call to OpenSocket)
|
||||
if(!_.contains($location.$$url, '/login')){
|
||||
$rootScope.sessionTimer = Timer.init();
|
||||
$rootScope.$emit('OpenSocket');
|
||||
pendoService.issuePendoIdentity();
|
||||
Timer.init().then(function(timer){
|
||||
$rootScope.sessionTimer = timer;
|
||||
$rootScope.$emit('OpenSocket');
|
||||
pendoService.issuePendoIdentity();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ export default
|
||||
x = Store('sessionTime');
|
||||
x[$rootScope.current_user.id].loggedIn = false;
|
||||
Store('sessionTime', x);
|
||||
|
||||
|
||||
$rootScope.lastUser = $cookieStore.get('current_user').id;
|
||||
$cookieStore.remove('token_expires');
|
||||
$cookieStore.remove('current_user');
|
||||
@ -98,7 +98,7 @@ export default
|
||||
$rootScope.token_expires = null;
|
||||
$rootScope.login_username = null;
|
||||
$rootScope.login_password = null;
|
||||
$rootScope.sessionTimer.expireSession();
|
||||
$rootScope.sessionTimer.clearTimers();
|
||||
},
|
||||
|
||||
getLicense: function () {
|
||||
@ -153,7 +153,6 @@ export default
|
||||
// store the response values in $rootScope so we can get to them later
|
||||
$rootScope.current_user = response.results[0];
|
||||
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
|
||||
$rootScope.$emit('OpenSocket');
|
||||
},
|
||||
|
||||
restoreUserInfo: function () {
|
||||
|
||||
@ -23,9 +23,9 @@
|
||||
*/
|
||||
export default
|
||||
['$rootScope', '$cookieStore', 'transitionTo', 'CreateDialog', 'Authorization',
|
||||
'Store', '$interval',
|
||||
'Store', '$interval', '$location', '$q',
|
||||
function ($rootScope, $cookieStore, transitionTo, CreateDialog, Authorization,
|
||||
Store, $interval) {
|
||||
Store, $interval, $location, $q) {
|
||||
return {
|
||||
|
||||
sessionTime: null,
|
||||
@ -82,7 +82,6 @@ export default
|
||||
this.sessionTime = 0;
|
||||
this.clearTimers();
|
||||
$cookieStore.put('sessionExpired', true);
|
||||
transitionTo('signOut');
|
||||
},
|
||||
|
||||
moveForward: function () {
|
||||
@ -158,9 +157,14 @@ export default
|
||||
$('#idle-modal').dialog('close');
|
||||
}
|
||||
that.expireSession('idle');
|
||||
$location.url('/login');
|
||||
}
|
||||
if(Store('sessionTime')[$rootScope.current_user.id].loggedIn === false){
|
||||
that.expireSession();
|
||||
if(Store('sessionTime') &&
|
||||
Store('sessionTime')[$rootScope.current_user.id] &&
|
||||
Store('sessionTime')[$rootScope.current_user.id].loggedIn === false){
|
||||
that.expireSession();
|
||||
$location.url('/login');
|
||||
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
@ -169,11 +173,15 @@ export default
|
||||
|
||||
clearTimers: function(){
|
||||
$interval.cancel($rootScope.expireTimer);
|
||||
delete $rootScope.expireTimer;
|
||||
},
|
||||
|
||||
init: function () {
|
||||
var deferred = $q.defer();
|
||||
this.moveForward();
|
||||
return this;
|
||||
deferred.resolve(this);
|
||||
return deferred.promise;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -165,9 +165,12 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l
|
||||
Authorization.getUser()
|
||||
.success(function (data) {
|
||||
Authorization.setUserInfo(data);
|
||||
$rootScope.sessionTimer = Timer.init();
|
||||
$rootScope.user_is_superuser = data.results[0].is_superuser;
|
||||
scope.$emit('AuthorizationGetLicense');
|
||||
Timer.init().then(function(timer){
|
||||
$rootScope.sessionTimer = timer;
|
||||
$rootScope.$emit('OpenSocket');
|
||||
$rootScope.user_is_superuser = data.results[0].is_superuser;
|
||||
scope.$emit('AuthorizationGetLicense');
|
||||
});
|
||||
})
|
||||
.error(function (data, status) {
|
||||
Authorization.logout();
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
*************************************************/
|
||||
|
||||
export default
|
||||
[ '$rootScope', '$q',
|
||||
function ($rootScope, $q) {
|
||||
[ '$rootScope', '$q', '$injector',
|
||||
function ($rootScope, $q, $injector) {
|
||||
return {
|
||||
response: function(config) {
|
||||
if(config.headers('auth-token-timeout') !== null){
|
||||
@ -23,6 +23,8 @@
|
||||
responseError: function(rejection){
|
||||
if(rejection && rejection.data && rejection.data.detail && rejection.data.detail === "Maximum per-user sessions reached"){
|
||||
$rootScope.sessionTimer.expireSession('session_limit');
|
||||
var location = $injector.get('$location');
|
||||
location.url('/login');
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
return $q.reject(rejection);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user