Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b923c1d

Browse files
committed
Revert "Merge pull request witoldsz#10 from qloo/master"
This reverts commit 2c164df, reversing changes made to 5638403.
1 parent 2c164df commit b923c1d

File tree

1 file changed

+21
-70
lines changed

1 file changed

+21
-70
lines changed

src/angular-http-auth.js

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,78 @@
1-
/*global angular:true, browser:true */
2-
31
/**
42
* @license HTTP Auth Interceptor Module for AngularJS
53
* (c) 2012 Witold Szczerba
64
* License: MIT
75
*/
86
angular.module('http-auth-interceptor', [])
97

10-
.provider('authService', function () {
8+
.provider('authService', function() {
119
/**
1210
* Holds all the requests which failed due to 401 response,
1311
* so they can be re-requested in future, once login is completed.
1412
*/
1513
var buffer = [];
16-
17-
/**
18-
* Holds a list of functions that define rules for ignoring
19-
* the addition of requests to the buffer.
20-
*/
21-
var ignoreUrlExpressions = [];
22-
23-
/**
24-
* Adds functions to the `ignoreUrlExpressions` array.
25-
* The fn function takes a URL as a response as an argument and returns
26-
* `true` (to ignore the URL) or `false` (to allow the URL). When `true` is
27-
* returned no other expressions will be tested.
28-
*/
29-
this.addIgnoreUrlExpression = function (fn) {
30-
if (angular.isFunction(fn)) { ignoreUrlExpressions.push(fn); }
31-
return this;
32-
};
33-
34-
/**
35-
* Executes each of the ignore expressions to determine whether the URL
36-
* should be ignored.
37-
*
38-
* Example:
39-
*
40-
* angular.module('mod', ['http-auth-interceptor'])
41-
* .config(function (authServiceProvider) {
42-
* authServiceProvider.addIgnoreUrlExpression(function (response) {
43-
* return response.config.url === "/api/auth";
44-
* });
45-
* });
46-
*/
47-
this.shouldIgnoreUrl = function (response) {
48-
var fn, i, j = ignoreUrlExpressions.length;
49-
50-
for (i = 0; i < j; i++) {
51-
fn = ignoreUrlExpressions[i];
52-
if (fn(response) === true) { return true; }
53-
}
54-
55-
return false;
56-
};
57-
14+
5815
/**
5916
* Required by HTTP interceptor.
6017
* Function is attached to provider to be invisible for regular users of this service.
6118
*/
62-
this.pushToBuffer = function (config, deferred) {
19+
this.pushToBuffer = function(config, deferred) {
6320
buffer.push({
64-
config: config,
21+
config: config,
6522
deferred: deferred
6623
});
67-
};
68-
69-
this.$get = ['$rootScope', '$injector', function ($rootScope, $injector) {
24+
}
25+
26+
this.$get = ['$rootScope','$injector', function($rootScope, $injector) {
7027
var $http; //initialized later because of circular dependency problem
7128
function retry(config, deferred) {
7229
$http = $http || $injector.get('$http');
73-
$http(config).then(function (response) {
30+
$http(config).then(function(response) {
7431
deferred.resolve(response);
7532
});
7633
}
7734
function retryAll() {
78-
var i;
79-
80-
for (i = 0; i < buffer.length; ++i) {
35+
for (var i = 0; i < buffer.length; ++i) {
8136
retry(buffer[i].config, buffer[i].deferred);
8237
}
8338
buffer = [];
8439
}
8540

8641
return {
87-
loginConfirmed: function () {
42+
loginConfirmed: function() {
8843
$rootScope.$broadcast('event:auth-loginConfirmed');
8944
retryAll();
9045
}
91-
};
92-
}];
46+
}
47+
}]
9348
})
9449

9550
/**
9651
* $http interceptor.
9752
* On 401 response - it stores the request and broadcasts 'event:angular-auth-loginRequired'.
9853
*/
99-
.config(['$httpProvider', 'authServiceProvider', function ($httpProvider, authServiceProvider) {
100-
101-
var interceptor = ['$rootScope', '$q', function ($rootScope, $q) {
54+
.config(['$httpProvider', 'authServiceProvider', function($httpProvider, authServiceProvider) {
55+
56+
var interceptor = ['$rootScope', '$q', function($rootScope, $q) {
10257
function success(response) {
10358
return response;
10459
}
105-
60+
10661
function error(response) {
10762
if (response.status === 401) {
10863
var deferred = $q.defer();
109-
110-
if (!authServiceProvider.shouldIgnoreUrl(response)) {
111-
authServiceProvider.pushToBuffer(response.config, deferred);
112-
}
113-
64+
authServiceProvider.pushToBuffer(response.config, deferred);
11465
$rootScope.$broadcast('event:auth-loginRequired');
11566
return deferred.promise;
11667
}
11768
// otherwise
11869
return $q.reject(response);
11970
}
120-
121-
return function (promise) {
71+
72+
return function(promise) {
12273
return promise.then(success, error);
123-
};
124-
74+
}
75+
12576
}];
12677
$httpProvider.responseInterceptors.push(interceptor);
12778
}]);

0 commit comments

Comments
 (0)