From 5f52384a3d5add5fcae0bdb0865199b416a96d85 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Tue, 24 May 2016 15:20:23 -0700 Subject: [PATCH] fixing login and submit for new license --- awx/ui/client/src/app.js | 9 +++- .../src/license/checkLicense.factory.js | 17 ++++--- .../client/src/license/license.controller.js | 44 ++++++++++--------- .../authentication.service.js | 16 ++++--- .../login/loginModal/loginModal.controller.js | 19 ++++---- .../src/shared/config/config.service.js | 10 +++-- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 9eba128abb..ef11461b7b 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -879,7 +879,14 @@ var tower = angular.module('Tower', [ $rootScope.$emit('OpenSocket'); ConfigService.getConfig().then(function(){ pendoService.issuePendoIdentity(); - CheckLicense.test(event); + CheckLicense.test().then(function(){ + // $state.go(next); + return; + }) + .catch(function(){ + event.preventDefault(); + $state.go('license'); + }); }); }); } diff --git a/awx/ui/client/src/license/checkLicense.factory.js b/awx/ui/client/src/license/checkLicense.factory.js index cb686ce4d5..2791bfaafe 100644 --- a/awx/ui/client/src/license/checkLicense.factory.js +++ b/awx/ui/client/src/license/checkLicense.factory.js @@ -6,8 +6,8 @@ export default ['$state', '$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', '$q', - 'Store', 'ConfigService', - function($state, $rootScope, Rest, GetBasePath, ProcessErrors, $q, Store, + 'ConfigService', + function($state, $rootScope, Rest, GetBasePath, ProcessErrors, $q, ConfigService){ return { get: function() { @@ -46,7 +46,7 @@ export default return true; }, test: function(event){ - var //deferred = $q.defer(), + var deferred = $q.defer(), license = this.get(); if(license === null || !$rootScope.license_tested){ if(this.valid(license) === false) { @@ -55,11 +55,11 @@ export default event.preventDefault(); } $state.go('license'); - // deferred.reject(); + deferred.reject(); } else { $rootScope.licenseMissing = false; - // deferred.resolve(); + deferred.resolve(); } } else if(this.valid(license) === false) { @@ -68,14 +68,13 @@ export default if(event){ event.preventDefault(); } - // deferred.reject(license); + deferred.reject(license); } else { $rootScope.licenseMissing = false; - // deferred.resolve(license); + deferred.resolve(license); } - return; - // return deferred.promise; + return deferred.promise; } }; diff --git a/awx/ui/client/src/license/license.controller.js b/awx/ui/client/src/license/license.controller.js index b210bd5a0b..6fb1c84d48 100644 --- a/awx/ui/client/src/license/license.controller.js +++ b/awx/ui/client/src/license/license.controller.js @@ -7,8 +7,9 @@ export default ['Wait', '$state', '$scope', '$rootScope', '$location', 'GetBasePath', 'Rest', 'ProcessErrors', 'CheckLicense', 'moment','$window', + 'ConfigService', function( Wait, $state, $scope, $rootScope, $location, GetBasePath, Rest, - ProcessErrors, CheckLicense, moment, $window){ + ProcessErrors, CheckLicense, moment, $window, ConfigService){ $scope.getKey = function(event){ // Mimic HTML5 spec, show filename $scope.fileName = event.target.files[0].name; @@ -47,20 +48,24 @@ export default .success(function(){ reset(); init(); - if($rootScope.licenseMissing === true){ - $state.go('dashboard', { - licenseMissing: false - }); - } - else{ - $scope.success = true; - $rootScope.licenseMissing = false; - // for animation purposes - var successTimeout = setTimeout(function(){ - $scope.success = false; - clearTimeout(successTimeout); - }, 4000); - } + ConfigService.delete(); + ConfigService.getConfig().then(function(){ + if($rootScope.licenseMissing === true){ + $state.go('dashboard', { + licenseMissing: false + }); + } + else{ + $scope.success = true; + $rootScope.licenseMissing = false; + // for animation purposes + var successTimeout = setTimeout(function(){ + $scope.success = false; + clearTimeout(successTimeout); + }, 4000); + } + }); + }); }; var calcDaysRemaining = function(seconds){ @@ -80,16 +85,15 @@ export default $scope.fileName = "No file selected."; $scope.title = $rootScope.licenseMissing ? "Tower License" : "License Management"; Wait('start'); - var license = CheckLicense.get(); - //.then(function(res){ - $scope.license = license; - $scope.license.version = license.version.split('-')[0]; + ConfigService.getConfig().then(function(config){ + $scope.license = config; + $scope.license.version = config.version.split('-')[0]; $scope.time = {}; $scope.time.remaining = calcDaysRemaining($scope.license.license_info.time_remaining); $scope.time.expiresOn = calcExpiresOn($scope.time.remaining); $scope.valid = CheckLicense.valid($scope.license.license_info); Wait('stop'); - // }); + }); }; var reset = function(){ document.getElementById('License-form').reset(); diff --git a/awx/ui/client/src/login/authenticationServices/authentication.service.js b/awx/ui/client/src/login/authenticationServices/authentication.service.js index 68e912c1a3..4846646d58 100644 --- a/awx/ui/client/src/login/authenticationServices/authentication.service.js +++ b/awx/ui/client/src/login/authenticationServices/authentication.service.js @@ -16,7 +16,9 @@ export default ['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath', 'Store', - function ($http, $rootScope, $location, $cookieStore, GetBasePath, Store) { + '$injector', + function ($http, $rootScope, $location, $cookieStore, GetBasePath, Store, + $injector) { return { setToken: function (token, expires) { // set the session cookie @@ -61,11 +63,12 @@ export default // the following puts our primary scope up for garbage collection, which // should prevent content flash from the prior user. - var x, scope = angular.element(document.getElementById('main-view')).scope(); + var x, + ConfigService = $injector.get('ConfigService'), + scope = angular.element(document.getElementById('main-view')).scope(); scope.$destroy(); //$rootScope.$destroy(); - if($cookieStore.get('lastPath')==='/portal'){ $cookieStore.put( 'lastPath', '/portal'); $rootScope.lastPath = '/portal'; @@ -88,6 +91,7 @@ export default if ($cookieStore.get('current_user')) { $rootScope.lastUser = $cookieStore.get('current_user').id; } + ConfigService.delete(); $cookieStore.remove('token_expires'); $cookieStore.remove('current_user'); $cookieStore.remove('token'); @@ -125,10 +129,10 @@ export default license.version = data.version; license.ansible_version = data.ansible_version; license.tested = false; - Store('license', license); - $rootScope.features = Store('license').features; + + $rootScope.features = license.features; }, - + licenseTested: function () { var license, result; if ($rootScope.license_tested !== undefined) { diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index 5e13da141f..c2793c5223 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -54,10 +54,12 @@ * This is usage information. */ -export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait', - 'Timer', 'Empty', 'ClearScope', '$scope', 'pendoService', - function ($log, $cookieStore, $compile, $window, $rootScope, $location, Authorization, ToggleClass, Alert, Wait, - Timer, Empty, ClearScope, scope, pendoService) { +export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', + '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait', 'Timer', + 'Empty', 'ClearScope', '$scope', 'pendoService', 'ConfigService', + function ($log, $cookieStore, $compile, $window, $rootScope, $location, + Authorization, ToggleClass, Alert, Wait, Timer, Empty, ClearScope, + scope, pendoService, ConfigService) { var lastPath, lastUser, sessionExpired, loginAgain; @@ -110,9 +112,10 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l scope.removeAuthorizationGetLicense(); } scope.removeAuthorizationGetLicense = scope.$on('AuthorizationGetLicense', function() { - Authorization.getLicense() - .success(function (data) { - Authorization.setLicense(data); + // Authorization.getLicense() + // .success(function (data) { + // Authorization.setLicense(data); + ConfigService.getConfig().then(function(){ pendoService.issuePendoIdentity(); Wait("stop"); if (lastPath() && lastUser()) { @@ -122,7 +125,7 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l $location.url('/home'); } }) - .error(function () { + .catch(function () { Wait('stop'); Alert('Error', 'Failed to access license information. GET returned status: ' + status, 'alert-danger', loginAgain); }); diff --git a/awx/ui/client/src/shared/config/config.service.js b/awx/ui/client/src/shared/config/config.service.js index 4df049068d..95d1a0f86a 100644 --- a/awx/ui/client/src/shared/config/config.service.js +++ b/awx/ui/client/src/shared/config/config.service.js @@ -6,8 +6,8 @@ export default - [ '$rootScope', '$pendolytics', 'Rest', 'GetBasePath', 'ProcessErrors', '$q', - function ($rootScope, $pendolytics, Rest, GetBasePath, ProcessErrors, $q) { + ['GetBasePath', 'ProcessErrors', '$q', 'Rest', '$rootScope', + function (GetBasePath, ProcessErrors, $q, Rest, $rootScope) { return { get: function(){ return this.config; @@ -17,6 +17,10 @@ export default this.config = config; }, + delete: function(){ + delete(this.config); + }, + getConfig: function () { var config = this.get(), that = this, @@ -33,7 +37,7 @@ export default promise.catch(function (response) { ProcessErrors($rootScope, response.data, response.status, null, { hdr: 'Error!', - msg: 'Failed to get inventory name. GET returned status: ' + + msg: 'Failed to get config. GET returned status: ' + response.status }); deferred.reject('Could not resolve pendo config.'); });