OSDN Git Service

signup page authentication
[eos/zephyr.git] / client / app / app.js
index d64f304..b86b968 100644 (file)
@@ -8,21 +8,21 @@ angular.module('zephyrApp', ['ui.bootstrap', 'ui.router', 'restangular','ngRoute
     })
     $urlRouterProvider.otherwise('/login')
     $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
-
-    $httpProvider.interceptors.push(function($q, $location) { 
-        return { 
-            response: function(response) { // do something on success 
-                return response 
-            }, 
-            responseError: function(response) { 
-                if (response.status === 401) $location.url('/login') 
-                    return $q.reject(response); 
-            } 
-        }; 
-    })
 })
-.run(function($rootScope, $state) {
+.run(function($rootScope, $state, Restangular) {
     $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
         $rootScope.previous = fromState.name
     })
+
+    Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
+        if(response.status === 401) {
+            $state.go('login')
+        }
+        else if(response.status === 409) {
+            // send signal to SignupController
+            $rootScope.$broadcast('conflict')
+        }
+
+        return false
+    })
 })