diff --git a/traffic_portal/app/src/common/api/AuthService.js b/traffic_portal/app/src/common/api/AuthService.js index 439390a146..7543cdacbf 100644 --- a/traffic_portal/app/src/common/api/AuthService.js +++ b/traffic_portal/app/src/common/api/AuthService.js @@ -17,64 +17,60 @@ * under the License. */ -var AuthService = function($rootScope, $http, $state, $location, $q, $state, httpService, userModel, messageModel, ENV) { +var AuthService = function($rootScope, $http, $state, $location, userModel, messageModel, ENV) { this.login = function(username, password) { userModel.resetUser(); - return httpService.post(ENV.api['root'] + 'user/login', { u: username, p: password }) - .then( - function(result) { - $rootScope.$broadcast('authService::login'); - var redirect = decodeURIComponent($location.search().redirect); - if (redirect !== 'undefined') { - $location.search('redirect', null); // remove the redirect query param - $location.url(redirect); - } else { - $location.url('/'); - } - }, - function(fault) { - // do nothing + return $http.post(ENV.api['root'] + 'user/login', { u: username, p: password }).then( + function(result) { + $rootScope.$broadcast('authService::login'); + const redirect = decodeURIComponent($location.search().redirect); + if (redirect !== 'undefined') { + $location.search('redirect', null); // remove the redirect query param + $location.url(redirect); + } else { + $location.url('/'); } - ); + return result; + }, + function(err) { + throw err; + } + ); }; this.tokenLogin = function(token) { - var deferred = $q.defer(); - userModel.resetUser(); - - $http.post(ENV.api['root'] + "user/login/token", { t: token }) - .then( - function() { - deferred.resolve(); - }, - function() { - deferred.reject(); - } - ); - - return deferred.promise; + return $http.post(ENV.api['root'] + "user/login/token", { t: token }).then( + function(result) { + return result; + }, + function(err) { + throw err; + } + ); }; this.logout = function() { userModel.resetUser(); - httpService.post(ENV.api['root'] + 'user/logout'). - then( - function(result) { - $rootScope.$broadcast('trafficPortal::exit'); - if ($state.current.name == 'trafficPortal.public.login') { - messageModel.setMessages(result.alerts, false); - } else { - messageModel.setMessages(result.alerts, true); - $state.go('trafficPortal.public.login'); - } - return result; + return $http.post(ENV.api['root'] + 'user/logout').then( + function(result) { + $rootScope.$broadcast('trafficPortal::exit'); + if ($state.current.name == 'trafficPortal.public.login') { + messageModel.setMessages(result.alerts, false); + } else { + messageModel.setMessages(result.alerts, true); + $state.go('trafficPortal.public.login'); } + return result; + }, + function(err) { + throw err; + } ); }; }; -AuthService.$inject = ['$rootScope', '$http', '$state', '$location', '$q', '$state', 'httpService', 'userModel', 'messageModel', 'ENV']; +AuthService.$inject = ['$rootScope', '$http', '$state', '$location', 'userModel', 'messageModel', 'ENV']; module.exports = AuthService; diff --git a/traffic_portal/app/src/modules/public/login/LoginController.js b/traffic_portal/app/src/modules/public/login/LoginController.js index 33bb557c11..374177c03e 100644 --- a/traffic_portal/app/src/modules/public/login/LoginController.js +++ b/traffic_portal/app/src/modules/public/login/LoginController.js @@ -24,15 +24,15 @@ var LoginController = function($scope, $log, $uibModal, authService, userService password: '' }; - $scope.login = function($event, credentials) { - var $btn = $($event.target); - $btn.prop('disabled', true); // disable the login button to prevent multiple clicks - authService.login(credentials.username, credentials.password) - .then( - function() { - $btn.prop('disabled', false); // re-enable it - } - ); + $scope.login = function(event, credentials) { + event.stopImmediatePropagation(); + const btn = event.currentTarget; + btn.disabled = true; // disable the login button to prevent multiple clicks + authService.login(credentials.username, credentials.password).finally( + function() { + btn.disabled = false; // re-enable it + } + ); }; $scope.resetPassword = function() {