1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

fixing login and submit for new license

This commit is contained in:
Jared Tabor 2016-05-24 15:20:23 -07:00
parent 8b271c4caf
commit 5f52384a3d
6 changed files with 68 additions and 47 deletions

View File

@ -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');
});
});
});
}

View File

@ -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;
}
};

View File

@ -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();

View File

@ -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) {

View File

@ -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);
});

View File

@ -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.');
});