Skip to content

Commit

Permalink
Angular 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMikeSimon committed Jun 22, 2016
1 parent 21d8c1e commit d30c2ce
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 60 deletions.
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"./build/secure-ng-resource.min.js"
],
"dependencies": {
"angular": "1.2.*",
"angular-cookies": "1.2.*",
"angular-resource": "1.2.*",
"angular": "1.5.*",
"angular-cookies": "1.5.*",
"angular-resource": "1.5.*",
"base-64": "0.1.*"
},
"devDependencies": {
"angular-mocks": "1.2.28",
"angular-mocks": "1.5.*",
"jasmine": "1.2.0"
}
}
53 changes: 30 additions & 23 deletions build/secure-ng-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* secure-ng-resource JavaScript Library
* https://github.com/AmericanCouncils/secure-ng-resource/
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/23/2015 10:04
* Compiled At: 06/22/2016 16:08
***********************************************/
(function(window) {
'use strict';
Expand All @@ -27,7 +27,7 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {

var sessionDictionary = {};

var AuthSession = function (auth, settings) {
function AuthSession(auth, settings) {
this.auth = auth;
this.settings = angular.extend(
{},
Expand All @@ -52,7 +52,7 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {
} else {
this.reset();
}
};
}

AuthSession.prototype = {
getUserName: function () {
Expand Down Expand Up @@ -227,7 +227,8 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {
};

var AuthSessionFactory = function(auth, settings) {
return new AuthSession(auth, settings);
var as = new AuthSession(auth, settings);
return as;
};
AuthSessionFactory.dictionary = sessionDictionary;
return AuthSessionFactory;
Expand Down Expand Up @@ -645,29 +646,35 @@ angular.module('secureNgResource')
'use strict';

angular.module('secureNgResource')
.config([
'$httpProvider',
function($httpProvider) {$httpProvider.responseInterceptors.push([
'authSession', '$q',
function(authSession, $q) {
var responder = function(response) {
var ses = authSession.dictionary[response.config.sessionDictKey];
if (ses) {
return ses.handleHttpResponse(response);
} else {
return response;
}
};
.factory('secureResourceHttpInterceptor', [
'authSession', '$q',
function(authSession, $q) {
var responder = function(response) {
var ses = authSession.dictionary[response.config.sessionDictKey];
if (ses) {
return ses.handleHttpResponse(response);
} else {
return response;
}
};

var errorResponder = function(response) {
return {
response: function(response) {
return responder(response);
},

responseError: function(response) {
response = responder(response);
return $q.reject(response);
};
}
};
}]);

return function(promise) {
return promise.then(responder, errorResponder);
};
}]);
angular.module('secureNgResource')
.config([
'$httpProvider',
function($httpProvider) {
$httpProvider.interceptors.push('secureResourceHttpInterceptor');
}]);

}(window));
2 changes: 1 addition & 1 deletion build/secure-ng-resource.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
"angular": "1.2.x"
},
"devDependencies": {
"jasmine-node": "1.2.0",
"grunt-karma": "0.8.2",
"grunt-contrib-uglify": "0.4.0",
"grunt-contrib-jshint": "0.10.0",
"bower": "1.3.8",
"grunt": "0.4.5",
"grunt-cli": "0.1.6",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-uglify": "0.4.0",
"grunt-jsdoc": "0.5.4",
"grunt-cli": "0.1.6",
"grunt-karma": "0.8.2",
"jasmine-node": "1.2.0",
"karma": "0.12.31",
"karma-jasmine": "0.1.5",
"karma-phantomjs-launcher": "0.1.4",
"bower": "1.3.8"
"phantomjs-polyfill": "0.0.2"
}
}
47 changes: 25 additions & 22 deletions src/httpInterceptor.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
'use strict';

angular.module('secureNgResource')
.config([
'$httpProvider',
function($httpProvider) {
// TODO Interceptors are deprecated, but we need access to the
// status code of the response and transformResponse cannot get us that.
$httpProvider.responseInterceptors.push([
'authSession', '$q',
function(authSession, $q) {
var responder = function(response) {
var ses = authSession.dictionary[response.config.sessionDictKey];
if (ses) {
return ses.handleHttpResponse(response);
} else {
return response;
}
};
.factory('secureResourceHttpInterceptor', [
'authSession', '$q',
function(authSession, $q) {
var responder = function(response) {
var ses = authSession.dictionary[response.config.sessionDictKey];
if (ses) {
return ses.handleHttpResponse(response);
} else {
return response;
}
};

var errorResponder = function(response) {
return {
response: function(response) {
return responder(response);
},

responseError: function(response) {
response = responder(response);
return $q.reject(response);
};
}
};
}]);

return function(promise) {
return promise.then(responder, errorResponder);
};
}]);
angular.module('secureNgResource')
.config([
'$httpProvider',
function($httpProvider) {
$httpProvider.interceptors.push('secureResourceHttpInterceptor');
}]);
7 changes: 4 additions & 3 deletions src/services/AuthSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {

var sessionDictionary = {};

var AuthSession = function (auth, settings) {
function AuthSession(auth, settings) {
this.auth = auth;
this.settings = angular.extend(
{},
Expand All @@ -39,7 +39,7 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {
} else {
this.reset();
}
};
}

AuthSession.prototype = {
getUserName: function () {
Expand Down Expand Up @@ -226,7 +226,8 @@ function($q, $location, $cookieStore, $injector, $rootScope, $timeout) {
};

var AuthSessionFactory = function(auth, settings) {
return new AuthSession(auth, settings);
var as = new AuthSession(auth, settings);
return as;
};
AuthSessionFactory.dictionary = sessionDictionary;
return AuthSessionFactory;
Expand Down
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function(config) {
frameworks: ['jasmine'],

files: [
'node_modules/phantomjs-polyfill/bind-polyfill.js',
'bower_components/angular/angular.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
Expand Down
4 changes: 3 additions & 1 deletion test/unit/AuthSessionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe('AuthSession', function () {
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
cookieStore.remove('foo-spyAuth');
cookieStore.remove('angular-spyAuth');
});

it('has the correct initial state by default', function() {
Expand Down Expand Up @@ -116,7 +118,7 @@ describe('AuthSession', function () {
});

it('denies logins which the authenticator does not approve', function() {
auth.checkLoginResult = { status: 'denied', msg: 'And stay out' };
auth.checkLoginResult = { status: 'denied', msg: 'And stay out' };
ses.login({user: 'alice', pass: 'swordfish'});
$scope.$apply();
expect(ses.getUserName()).toBeUndefined();
Expand Down

0 comments on commit d30c2ce

Please sign in to comment.