trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mitchell...@apache.org
Subject [trafficcontrol] branch master updated: Removed restangular from AuthService.js (#3601)
Date Fri, 26 Jul 2019 21:59:24 GMT
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new c98cce9  Removed restangular from AuthService.js (#3601)
c98cce9 is described below

commit c98cce9b3d15fae88656d67cada079cc27cbbceb
Author: ocket8888 <ocket8888@gmail.com>
AuthorDate: Fri Jul 26 15:59:19 2019 -0600

    Removed restangular from AuthService.js (#3601)
    
    * Removed restangular from ./AuthService.js
    
    * fixed login button being permanently un-click-able after bad login
---
 traffic_portal/app/src/common/api/AuthService.js   | 80 ++++++++++------------
 .../src/modules/public/login/LoginController.js    | 18 ++---
 2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/traffic_portal/app/src/common/api/AuthService.js b/traffic_portal/app/src/common/api/AuthService.js
index 439390a..7543cda 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 33bb557..374177c 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() {


Mime
View raw message