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

@@ -10,12 +10,33 @@
'use strict';
function Authenticate($cookieStore, $window, $scope, $rootScope, $location, Authorization, ToggleClass, Alert, Wait)
function Authenticate($cookieStore, $window, $scope, $rootScope, $location, Authorization, ToggleClass, Alert, Wait,
Timer, Empty)
{
var setLoginFocus = function() {
$('#login-username').focus();
};
var sessionExpired = function() {
return (Empty($rootScope.sessionExpired)) ? $cookieStore.get('sessionExpired') : $rootScope.sessionExpired;
}();
var lastPath = function() {
return (Empty($rootScope.lastPath)) ? $cookieStore.get('lastPath') : $rootScope.lastPath;
}();
if ($AnsibleConfig.debug_mode && console) {
console.log('User session expired: ' + sessionExpired);
console.log('Last URL: ' + lastPath);
}
// Hide any lingering modal dialogs
$('.modal[aria-hidden=false]').each( function() {
if ($(this).attr('id') !== 'login-modal') {
$(this).modal('hide');
}
});
// Just in case, make sure the wait widget is not active
Wait('stop');
@@ -70,6 +91,7 @@ function Authenticate($cookieStore, $window, $scope, $rootScope, $location, Auth
$('#login-modal').modal('hide');
token = data.token;
Authorization.setToken(data.token, data.expires);
$rootScope.sessionTimer = Timer.init();
// Get all the profile/access info regarding the logged in user
Authorization.getUser()
.success(function(data, status, headers, config) {
@@ -77,7 +99,13 @@ function Authenticate($cookieStore, $window, $scope, $rootScope, $location, Auth
Authorization.getLicense()
.success(function(data, status, headers, config) {
Authorization.setLicense(data['license_info']);
$location.url('/home?login=true');
if (lastPath) {
// Go back to most recent navigation path
$location.path(lastPath);
}
else {
$location.url('/home?login=true');
}
})
.error(function(data, status, headers, config) {
Alert('Error', 'Failed to access user information. GET returned status: ' + status, 'alert-danger', setLoginFocus);
@@ -113,5 +141,6 @@ function Authenticate($cookieStore, $window, $scope, $rootScope, $location, Auth
}
}
Authenticate.$inject = ['$cookieStore', '$window', '$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait'];
Authenticate.$inject = ['$cookieStore', '$window', '$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait',
'Timer', 'Empty'];