mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-06 04:01:04 +01:00
Merge pull request #1107 from pgrodrigues/master
fix(core): Remove duplicate angular interceptor
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('core').factory('authInterceptor', ['$q', '$injector',
|
||||
function ($q, $injector) {
|
||||
angular.module('core').factory('authInterceptor', ['$q', '$injector', 'Authentication',
|
||||
function ($q, $injector, Authentication) {
|
||||
return {
|
||||
responseError: function(rejection) {
|
||||
if (!rejection.config.ignoreAuthModule) {
|
||||
switch (rejection.status) {
|
||||
case 401:
|
||||
// Deauthenticate the global user
|
||||
Authentication.user = null;
|
||||
$injector.get('$state').transitionTo('authentication.signin');
|
||||
break;
|
||||
case 403:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
var authInterceptor,
|
||||
$q,
|
||||
$state,
|
||||
Authentication,
|
||||
httpProvider;
|
||||
|
||||
// Load the main application module
|
||||
@@ -16,10 +17,11 @@
|
||||
httpProvider = $httpProvider;
|
||||
}));
|
||||
|
||||
beforeEach(inject(function(_authInterceptor_, _$q_, _$state_) {
|
||||
beforeEach(inject(function(_authInterceptor_, _$q_, _$state_, _Authentication_) {
|
||||
authInterceptor = _authInterceptor_;
|
||||
$q = _$q_;
|
||||
$state = _$state_;
|
||||
Authentication = _Authentication_;
|
||||
spyOn($q,'reject');
|
||||
spyOn($state,'transitionTo');
|
||||
}));
|
||||
@@ -56,6 +58,7 @@
|
||||
};
|
||||
var promise = authInterceptor.responseError(response);
|
||||
expect($q.reject).toHaveBeenCalled();
|
||||
expect(Authentication.user).toBe(null);
|
||||
expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// Config HTTP Error Handling
|
||||
angular.module('users').config(['$httpProvider',
|
||||
function ($httpProvider) {
|
||||
// Set the httpProvider "not authorized" interceptor
|
||||
$httpProvider.interceptors.push(['$q', '$location', 'Authentication',
|
||||
function ($q, $location, Authentication) {
|
||||
return {
|
||||
responseError: function (rejection) {
|
||||
switch (rejection.status) {
|
||||
case 401:
|
||||
// Deauthenticate the global user
|
||||
Authentication.user = null;
|
||||
|
||||
// Redirect to signin page
|
||||
$location.path('signin');
|
||||
break;
|
||||
case 403:
|
||||
// Add unauthorized behaviour
|
||||
break;
|
||||
}
|
||||
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
]);
|
||||
}
|
||||
]);
|
||||
Reference in New Issue
Block a user