mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 13:57:39 -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:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user