From 0b638c03d7965a68359b4e42bf0c4c628976f908 Mon Sep 17 00:00:00 2001 From: Ihor Karas Date: Fri, 7 Apr 2017 07:54:08 +0300 Subject: [PATCH] one more unneded rejection call by @MariuszHenn --- dist/ng-token-auth.js | 3 +-- dist/ng-token-auth.min.js | 2 +- src/ng-token-auth.coffee | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/ng-token-auth.js b/dist/ng-token-auth.js index 9a31838c..2add5f67 100644 --- a/dist/ng-token-auth.js +++ b/dist/ng-token-auth.js @@ -522,11 +522,10 @@ angular.module('ng-token-auth', ['ipCookie']).provider('$auth', function() { $rootScope.$broadcast('auth:password-reset-confirm-error', resp.data); } $rootScope.$broadcast('auth:validation-error', resp.data); - _this.rejectDfd({ + return _this.rejectDfd({ reason: 'unauthorized', errors: resp.data != null ? resp.data.errors : ['Unspecified error'] }, resp.status > 0); - return $q.reject(resp); }; })(this)); } else { diff --git a/dist/ng-token-auth.min.js b/dist/ng-token-auth.min.js index adc69d32..3f3d1152 100644 --- a/dist/ng-token-auth.min.js +++ b/dist/ng-token-auth.min.js @@ -1 +1 @@ -"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ng-token-auth"),angular.module("ng-token-auth",["ipCookie"]).provider("$auth",function(){var t,e;return t={"default":{apiUrl:"/api",signOutUrl:"/auth/sign_out",emailSignInPath:"/auth/sign_in",emailRegistrationPath:"/auth",accountUpdatePath:"/auth",accountDeletePath:"/auth",confirmationSuccessUrl:function(){return window.location.href},passwordResetPath:"/auth/password",passwordUpdatePath:"/auth/password",passwordResetSuccessUrl:function(){return window.location.href},tokenValidationPath:"/auth/validate_token",proxyIf:function(){return!1},proxyUrl:"/proxy",validateOnPageLoad:!0,omniauthWindowType:"sameWindow",storage:"cookies",forceValidateToken:!1,tokenFormat:{"access-token":"{{ token }}","token-type":"Bearer",client:"{{ clientId }}",expiry:"{{ expiry }}",uid:"{{ uid }}"},cookieOps:{path:"/",expires:9999,expirationUnit:"days",secure:!1},createPopup:function(t){return window.open(t,"_blank","closebuttoncaption=Cancel")},parseExpiry:function(t){return 1e3*parseInt(t.expiry,10)||null},handleLoginResponse:function(t){return t.data},handleAccountUpdateResponse:function(t){return t.data},handleTokenValidationResponse:function(t){return t.data},authProviderPaths:{github:"/auth/github",facebook:"/auth/facebook",google:"/auth/google_oauth2"}}},e="default",{configure:function(n){var i,r,a,s,o,u,c,h,d;if(n instanceof Array&&n.length){for(s=h=0,d=n.length;h0&&(d+="?"+this.buildQueryString(s)),a.url(d)):this.retrieveData("currentConfigName")&&(n=this.retrieveData("currentConfigName")),this.getConfig().forceValidateToken?this.validateToken({config:n}):isEmpty(this.retrieveData("auth_headers"))?(this.rejectDfd({reason:"unauthorized",errors:["No credentials"]}),c.$broadcast("auth:invalid")):this.tokenHasExpired()?(c.$broadcast("auth:session-expired"),this.rejectDfd({reason:"unauthorized",errors:["Session expired."]})):this.validateToken({config:n}))),this.dfd.promise},validateToken:function(t){return null==t&&(t={}),this.tokenHasExpired()?this.rejectDfd({reason:"unauthorized",errors:["Expired credentials"]}):i.get(this.apiUrl(t.config)+this.getConfig(t.config).tokenValidationPath).then(function(e){return function(n){var i;return i=e.getConfig(t.config).handleTokenValidationResponse(n.data),e.handleValidAuth(i),e.firstTimeLogin&&c.$broadcast("auth:email-confirmation-success",e.user),e.oauthRegistration&&c.$broadcast("auth:oauth-registration",e.user),e.mustResetPassword&&c.$broadcast("auth:password-reset-confirm-success",e.user),c.$broadcast("auth:validation-success",e.user)}}(this),function(t){return function(e){return t.firstTimeLogin&&c.$broadcast("auth:email-confirmation-error",e.data),t.mustResetPassword&&c.$broadcast("auth:password-reset-confirm-error",e.data),c.$broadcast("auth:validation-error",e.data),t.rejectDfd({reason:"unauthorized",errors:null!=e.data?e.data.errors:["Unspecified error"]},e.status>0),r.reject(e)}}(this))},tokenHasExpired:function(){var t,e;return t=this.getExpiry(),e=(new Date).getTime(),t&&ti&&(null!=this.timer&&d.cancel(this.timer),this.timer=d(function(t){return function(){return t.validateUser({config:t.getSavedConfig()})}}(this),parseInt(e-i),1)),r},initDfd:function(){return this.dfd=r.defer(),this.dfd.promise.then(angular.noop,angular.noop)},rejectDfd:function(t,e){if(null==e&&(e=!0),e===!0&&this.invalidateTokens(),null!=this.dfd)return this.dfd.reject(t),u(function(t){return function(){return t.dfd=null}}(this),0)},apiUrl:function(t){return this.getConfig(t).proxyIf()?this.getConfig(t).proxyUrl:this.getConfig(t).apiUrl},getConfig:function(e){return t[this.getCurrentConfigName(e)]},getResultOrValue:function(t){return"function"==typeof t?t():t},getCurrentConfigName:function(t){return t||this.getSavedConfig()},getSavedConfig:function(){var t,n;return t=void 0,n="currentConfigName",this.hasLocalStorage()?null==t&&(t=JSON.parse(o.localStorage.getItem(n))):this.hasSessionStorage()&&null==t&&(t=JSON.parse(o.sessionStorage.getItem(n))),null==t&&(t=s(n)),t||e},hasSessionStorage:function(){var t;if(null==this._hasSessionStorage){this._hasSessionStorage=!1;try{o.sessionStorage.setItem("ng-token-auth-test","ng-token-auth-test"),o.sessionStorage.removeItem("ng-token-auth-test"),this._hasSessionStorage=!0}catch(e){t=e}}return this._hasSessionStorage},hasLocalStorage:function(){var t;if(null==this._hasLocalStorage){this._hasLocalStorage=!1;try{o.localStorage.setItem("ng-token-auth-test","ng-token-auth-test"),o.localStorage.removeItem("ng-token-auth-test"),this._hasLocalStorage=!0}catch(e){t=e}}return this._hasLocalStorage}}}}(this)]}}).config(["$httpProvider",function(t){var e,n,i;return n=function(t,e){var n,i;return i=Number(t.getExpiry()),n=Number(t.getConfig().parseExpiry(e||{})),n>=i},i=function(t,e){var i,r,a,s;r={},s=t.getConfig().tokenFormat;for(i in s)a=s[i],e.headers(i)&&(r[i]=e.headers(i));if(n(t,r))return t.setAuthHeaders(r)},t.interceptors.push(["$injector",function(t){return{request:function(e){return t.invoke(["$http","$auth",function(t,n){var i,r,a,s;if(e.url.match(n.apiUrl())){a=n.retrieveData("auth_headers"),s=[];for(i in a)r=a[i],s.push(e.headers[i]=r);return s}}]),e},response:function(e){return t.invoke(["$http","$auth",function(t,n){if(e.config.url.match(n.apiUrl()))return i(n,e)}]),e},responseError:function(e){return t.invoke(["$http","$auth",function(t,n){if(e.config.url.match(n.apiUrl()))return i(n,e)}]),t.get("$q").reject(e)}}}]),e=["get","post","put","patch","delete"],angular.forEach(e,function(e){var n;return null==(n=t.defaults.headers)[e]&&(n[e]={}),t.defaults.headers[e]["If-Modified-Since"]="Mon, 26 Jul 1997 05:00:00 GMT"})}]).run(["$auth","$window","$rootScope",function(t,e,n){return t.initialize()}]),window.isOldIE=function(){var t,e,n;return e=!1,t=navigator.userAgent.toLowerCase(),t&&t.indexOf("msie")!==-1&&(n=parseInt(t.split("msie")[1]),n<10&&(e=!0)),e},window.isIE=function(){var t;return t=navigator.userAgent.toLowerCase(),t&&t.indexOf("msie")!==-1||!!navigator.userAgent.match(/Trident.*rv\:11\./)},window.isEmpty=function(t){var e,n;if(!t)return!0;if(t.length>0)return!1;if(0===t.length)return!0;for(e in t)if(n=t[e],Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}; \ No newline at end of file +"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="ng-token-auth"),angular.module("ng-token-auth",["ipCookie"]).provider("$auth",function(){var t,e;return t={"default":{apiUrl:"/api",signOutUrl:"/auth/sign_out",emailSignInPath:"/auth/sign_in",emailRegistrationPath:"/auth",accountUpdatePath:"/auth",accountDeletePath:"/auth",confirmationSuccessUrl:function(){return window.location.href},passwordResetPath:"/auth/password",passwordUpdatePath:"/auth/password",passwordResetSuccessUrl:function(){return window.location.href},tokenValidationPath:"/auth/validate_token",proxyIf:function(){return!1},proxyUrl:"/proxy",validateOnPageLoad:!0,omniauthWindowType:"sameWindow",storage:"cookies",forceValidateToken:!1,tokenFormat:{"access-token":"{{ token }}","token-type":"Bearer",client:"{{ clientId }}",expiry:"{{ expiry }}",uid:"{{ uid }}"},cookieOps:{path:"/",expires:9999,expirationUnit:"days",secure:!1},createPopup:function(t){return window.open(t,"_blank","closebuttoncaption=Cancel")},parseExpiry:function(t){return 1e3*parseInt(t.expiry,10)||null},handleLoginResponse:function(t){return t.data},handleAccountUpdateResponse:function(t){return t.data},handleTokenValidationResponse:function(t){return t.data},authProviderPaths:{github:"/auth/github",facebook:"/auth/facebook",google:"/auth/google_oauth2"}}},e="default",{configure:function(n){var i,r,a,s,o,u,h,c,d;if(n instanceof Array&&n.length){for(s=c=0,d=n.length;c0&&(d+="?"+this.buildQueryString(s)),a.url(d)):this.retrieveData("currentConfigName")&&(n=this.retrieveData("currentConfigName")),this.getConfig().forceValidateToken?this.validateToken({config:n}):isEmpty(this.retrieveData("auth_headers"))?(this.rejectDfd({reason:"unauthorized",errors:["No credentials"]}),h.$broadcast("auth:invalid")):this.tokenHasExpired()?(h.$broadcast("auth:session-expired"),this.rejectDfd({reason:"unauthorized",errors:["Session expired."]})):this.validateToken({config:n}))),this.dfd.promise},validateToken:function(t){return null==t&&(t={}),this.tokenHasExpired()?this.rejectDfd({reason:"unauthorized",errors:["Expired credentials"]}):i.get(this.apiUrl(t.config)+this.getConfig(t.config).tokenValidationPath).then(function(e){return function(n){var i;return i=e.getConfig(t.config).handleTokenValidationResponse(n.data),e.handleValidAuth(i),e.firstTimeLogin&&h.$broadcast("auth:email-confirmation-success",e.user),e.oauthRegistration&&h.$broadcast("auth:oauth-registration",e.user),e.mustResetPassword&&h.$broadcast("auth:password-reset-confirm-success",e.user),h.$broadcast("auth:validation-success",e.user)}}(this),function(t){return function(e){return t.firstTimeLogin&&h.$broadcast("auth:email-confirmation-error",e.data),t.mustResetPassword&&h.$broadcast("auth:password-reset-confirm-error",e.data),h.$broadcast("auth:validation-error",e.data),t.rejectDfd({reason:"unauthorized",errors:null!=e.data?e.data.errors:["Unspecified error"]},e.status>0)}}(this))},tokenHasExpired:function(){var t,e;return t=this.getExpiry(),e=(new Date).getTime(),t&&ti&&(null!=this.timer&&d.cancel(this.timer),this.timer=d(function(t){return function(){return t.validateUser({config:t.getSavedConfig()})}}(this),parseInt(e-i),1)),r},initDfd:function(){return this.dfd=r.defer(),this.dfd.promise.then(angular.noop,angular.noop)},rejectDfd:function(t,e){if(null==e&&(e=!0),e===!0&&this.invalidateTokens(),null!=this.dfd)return this.dfd.reject(t),u(function(t){return function(){return t.dfd=null}}(this),0)},apiUrl:function(t){return this.getConfig(t).proxyIf()?this.getConfig(t).proxyUrl:this.getConfig(t).apiUrl},getConfig:function(e){return t[this.getCurrentConfigName(e)]},getResultOrValue:function(t){return"function"==typeof t?t():t},getCurrentConfigName:function(t){return t||this.getSavedConfig()},getSavedConfig:function(){var t,n;return t=void 0,n="currentConfigName",this.hasLocalStorage()?null==t&&(t=JSON.parse(o.localStorage.getItem(n))):this.hasSessionStorage()&&null==t&&(t=JSON.parse(o.sessionStorage.getItem(n))),null==t&&(t=s(n)),t||e},hasSessionStorage:function(){var t;if(null==this._hasSessionStorage){this._hasSessionStorage=!1;try{o.sessionStorage.setItem("ng-token-auth-test","ng-token-auth-test"),o.sessionStorage.removeItem("ng-token-auth-test"),this._hasSessionStorage=!0}catch(e){t=e}}return this._hasSessionStorage},hasLocalStorage:function(){var t;if(null==this._hasLocalStorage){this._hasLocalStorage=!1;try{o.localStorage.setItem("ng-token-auth-test","ng-token-auth-test"),o.localStorage.removeItem("ng-token-auth-test"),this._hasLocalStorage=!0}catch(e){t=e}}return this._hasLocalStorage}}}}(this)]}}).config(["$httpProvider",function(t){var e,n,i;return n=function(t,e){var n,i;return i=Number(t.getExpiry()),n=Number(t.getConfig().parseExpiry(e||{})),n>=i},i=function(t,e){var i,r,a,s;r={},s=t.getConfig().tokenFormat;for(i in s)a=s[i],e.headers(i)&&(r[i]=e.headers(i));if(n(t,r))return t.setAuthHeaders(r)},t.interceptors.push(["$injector",function(t){return{request:function(e){return t.invoke(["$http","$auth",function(t,n){var i,r,a,s;if(e.url.match(n.apiUrl())){a=n.retrieveData("auth_headers"),s=[];for(i in a)r=a[i],s.push(e.headers[i]=r);return s}}]),e},response:function(e){return t.invoke(["$http","$auth",function(t,n){if(e.config.url.match(n.apiUrl()))return i(n,e)}]),e},responseError:function(e){return t.invoke(["$http","$auth",function(t,n){if(e.config.url.match(n.apiUrl()))return i(n,e)}]),t.get("$q").reject(e)}}}]),e=["get","post","put","patch","delete"],angular.forEach(e,function(e){var n;return null==(n=t.defaults.headers)[e]&&(n[e]={}),t.defaults.headers[e]["If-Modified-Since"]="Mon, 26 Jul 1997 05:00:00 GMT"})}]).run(["$auth","$window","$rootScope",function(t,e,n){return t.initialize()}]),window.isOldIE=function(){var t,e,n;return e=!1,t=navigator.userAgent.toLowerCase(),t&&t.indexOf("msie")!==-1&&(n=parseInt(t.split("msie")[1]),n<10&&(e=!0)),e},window.isIE=function(){var t;return t=navigator.userAgent.toLowerCase(),t&&t.indexOf("msie")!==-1||!!navigator.userAgent.match(/Trident.*rv\:11\./)},window.isEmpty=function(t){var e,n;if(!t)return!0;if(t.length>0)return!1;if(0===t.length)return!0;for(e in t)if(n=t[e],Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}; \ No newline at end of file diff --git a/src/ng-token-auth.coffee b/src/ng-token-auth.coffee index 797584f1..a6618f8c 100644 --- a/src/ng-token-auth.coffee +++ b/src/ng-token-auth.coffee @@ -591,7 +591,6 @@ angular.module('ng-token-auth', ['ipCookie']) resp.status > 0 ) - $q.reject(resp) ) else @rejectDfd({