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

@@ -79,7 +79,8 @@ angular.module('ansible', [
'InventorySummaryHelpDefinition',
'InventoryHostsHelpDefinition',
'TreeSelector',
'CredentialsHelper'
'CredentialsHelper',
'TimerService'
])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.
@@ -248,25 +249,38 @@ angular.module('ansible', [
otherwise({redirectTo: '/home'});
}])
.run(['$cookieStore', '$rootScope', 'CheckLicense', '$location', 'Authorization','LoadBasePaths', 'ViewLicense',
function($cookieStore, $rootScope, CheckLicense, $location, Authorization, LoadBasePaths, ViewLicense) {
'Timer',
function($cookieStore, $rootScope, CheckLicense, $location, Authorization, LoadBasePaths, ViewLicense,
Timer) {
LoadBasePaths();
if ( !(typeof $AnsibleConfig.refresh_rate == 'number' && $AnsibleConfig.refresh_rate >= 3
&& $AnsibleConfig.refresh_rate <= 99) ) {
$AnsibleConfig.refresh_rate = 10;
}
$rootScope.breadcrumbs = new Array();
$rootScope.crumbCache = new Array();
$rootScope.sessionTimer = Timer.init();
$rootScope.$on("$routeChangeStart", function(event, next, current) {
// On each navigation request, check that the user is logged in
var tst = /login/;
var path = $location.path();
if ( !tst.test($location.path()) ) {
// capture most recent URL, excluding login
$rootScope.lastPath = path;
$cookieStore.put('lastPath', path);
}
if (Authorization.isUserLoggedIn() == false) {
if ( next.templateUrl != (urlPrefix + 'partials/login.html') ) {
$location.path('/login');
}
}
else if ($rootScope.sessionTimer.isExpired()) {
if ( next.templateUrl != (urlPrefix + 'partials/login.html') ) {
$rootScope.sessionTimer.expireSession();
$location.path('/login');
}
}
else {
if ($rootScope.current_user == undefined || $rootScope.current_user == null) {
Authorization.restoreUserInfo(); //user must have hit browser refresh

View File

@@ -14,13 +14,13 @@ var $AnsibleConfig =
debug_mode: true, // Enable console logging messages
refresh_rate: 10, // Number of seconds before refreshing a page. Integer between 3 and 99, inclusive.
// Used by awRefresh directive to automatically refresh Jobs and Projects pages.
password_strength: 45 // User password strength. Integer between 0 and 100, 100 being impossibly strong.
password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong.
// This value controls progress bar colors:
// 0 to password_strength - 15 = red;
// password_strength - 15 to password_strength = yellow
// > password_strength = green
// It also controls password validation. Passwords are rejected if the score is not > password_strength.
session_timeout: 15 // Number of seconds before an inactive session is automatically timed out and forced to log in again.
// Separate from time out value set in API.
}

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'];

View File

@@ -78,8 +78,8 @@ angular.module('JobTemplateFormDefinition', [])
sourceModel: 'credential',
sourceField: 'name',
ngClick: 'lookUpCredential()',
addRequired: false,
editRequired: false,
addRequired: true,
editRequired: true,
column: 1
},
cloud_credential: {

View File

@@ -65,7 +65,7 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper'])
var f = scope[iterator + 'SearchField']
if (list.fields[f].searchType && ( list.fields[f].searchType == 'boolean'
|| list.fields[f].searchType == 'select')) {
|| list.fields[f].searchType == 'select')) {
scope[iterator + 'SelectShow'] = true;
scope[iterator + 'SearchSelectOpts'] = list.fields[f].searchOptions;
}