UI side of the session limit

includes the 'control' socket, kicking the user out, and adjusting the
expireSession function based on the reason
This commit is contained in:
Jared Tabor
2015-10-01 16:38:37 -04:00
parent fd34854f7a
commit c96f0234f9
6 changed files with 37 additions and 11 deletions

View File

@@ -887,7 +887,7 @@ var tower = angular.module('Tower', [
// Listen for job changes and issue callbacks to initiate
// DOM updates
function openSocket() {
var schedule_socket;
var schedule_socket, control_socket;
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
sock.init();
@@ -936,6 +936,16 @@ var tower = angular.module('Tower', [
$log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status);
$rootScope.$emit('ScheduleStatusChange', data);
});
control_socket = Socket({
scope: $rootScope,
endpoint: "control"
});
control_socket.init();
control_socket.on("limit_reached", function(data) {
$log.debug(data.reason);
Timer.expireSession('session_limit');
});
}
openSocket();
@@ -982,7 +992,7 @@ var tower = angular.module('Tower', [
} else if ($rootScope.sessionTimer.isExpired()) {
// gets here on timeout
if (next.templateUrl !== (urlPrefix + 'login/loginBackDrop.partial.html')) {
$rootScope.sessionTimer.expireSession();
$rootScope.sessionTimer.expireSession('idle');
if (sock) {
sock.socket.socket.disconnect();
}

View File

@@ -59,9 +59,16 @@ export default
}
},
expireSession: function () {
expireSession: function (reason) {
if(reason === 'session_limit'){
$rootScope.sessionLimitExpired = true;
$rootScope.sessionExpired = false;
}
else if(reason === 'idle'){
$rootScope.sessionExpired = true;
$rootScope.sessionLimitExpired = false;
}
this.sessionTime = 0;
$rootScope.sessionExpired = true;
this.clearTimers();
$cookieStore.put('sessionExpired', true);
transitionTo('signOut');
@@ -89,7 +96,7 @@ export default
// make a timeout that will go off in 30 mins to log them out
// unless they extend their time
$rootScope.endTimer = setTimeout(function(){
that.expireSession();
that.expireSession('idle');
}, tm * 1000);
// notify the user a minute before the end of their session that

View File

@@ -6,13 +6,17 @@
ng-src="/static/assets/{{ customLogo }}" >
</div>
<div class="modal-body">
<div class="LoginModal-alert" ng-show="!sessionExpired">
<div class="LoginModal-alert" ng-show="!sessionExpired && !sessionLimitExpired">
Welcome to Ansible Tower! &nbsp;Please sign in.
</div>
<div class="LoginModal-alert" ng-show="sessionExpired">
Your session timed out due to inactivity. Please
sign in.
</div>
<div class="LoginModal-alert" ng-show="sessionLimitExpired">
Maximum per-user sessions reached. Please
sign in.
</div>
<form id="login-form"
name="loginForm"
class="form-horizontal"

View File

@@ -11,16 +11,21 @@
*************************************************/
export default
['$rootScope',
[ '$rootScope',
function ($rootScope) {
return {
response: function(config) {
if(config.headers('auth-token-timeout') !== null){
// $rootScope.sessionTimer = Number(config.headers('auth-token-timeout'));
$AnsibleConfig.session_timeout = Number(config.headers('auth-token-timeout'));
// $rootScope.sessionTimer = Timer.init();
}
return config;
},
responseError: function(rejection){
if(rejection.data.detail && rejection.data.detail === "Maximum per-user sessions reached"){
$rootScope.sessionTimer.expireSession('session_limit');
return rejection;
}
return rejection;
}
};
}];

View File

@@ -158,7 +158,7 @@ angular.module('SocketIO', ['Utilities'])
}
else {
// encountered expired token, redirect to login page
$rootScope.sessionTimer.expireSession();
$rootScope.sessionTimer.expireSession('idle');
$location.url('/login');
}
},

View File

@@ -200,7 +200,7 @@ angular.module('Utilities', ['RestServices', 'Utilities', 'sanitizeFilter'])
} else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') ||
(status === 401 && data.detail && data.detail === 'Invalid token')) {
if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.expireSession();
$rootScope.sessionTimer.expireSession('idle');
}
$location.url('/login');
} else if (data.non_field_errors) {