From fa76884b5b1384f361270b0b023fee4010c4f2a4 Mon Sep 17 00:00:00 2001 From: Nikolay Gerzhan Date: Thu, 18 Aug 2016 17:14:29 +0700 Subject: [PATCH 1/2] Fix jshint warnings --- src/auth.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/auth.js b/src/auth.js index 864e9c5..508f4bd 100644 --- a/src/auth.js +++ b/src/auth.js @@ -90,11 +90,11 @@ devise.provider('Auth', function AuthProvider() { // The baseUrl config function this.baseUrl = function(value) { - if (value === undefined) { - return baseUrl; - } - baseUrl = value; - return this; + if (value === undefined) { + return baseUrl; + } + baseUrl = value; + return this; }; // The resourceName config function From b5276b9125313425d314f54dddea726b9992dfca Mon Sep 17 00:00:00 2001 From: Nikolay Gerzhan Date: Thu, 18 Aug 2016 17:16:33 +0700 Subject: [PATCH 2/2] New build --- lib/devise-min.js | 4 ++-- lib/devise.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/devise-min.js b/lib/devise-min.js index 97a577f..42a73fa 100644 --- a/lib/devise-min.js +++ b/lib/devise-min.js @@ -1,10 +1,10 @@ // AngularDevise // ------------------- -// v1.2.1 +// v1.3.0 // // Copyright (c)2016 Justin Ridgewell // Distributed under MIT license // // https://github.com/cloudspace/angular_devise -!function(a){"use strict";var b=a.module("Devise",[]);b.provider("AuthIntercept",function(){var a=!1;this.interceptAuth=function(b){return a=!!b||void 0===b,this},this.$get=["$rootScope","$q",function(b,c){return{responseError:function(d){var e=d.config.interceptAuth;if(e=!!e||a&&void 0===e,e&&401===d.status){var f=c.defer();return b.$broadcast("devise:unauthorized",d,f),f.reject(d),f.promise}return c.reject(d)}}}]}).config(["$httpProvider",function(a){a.interceptors.push("AuthIntercept")}]),b.provider("Auth",function(){function b(b,c,d){var h={method:f[b].toLowerCase(),url:e[b]};return c&&(g?(h.data={},h.data[g]=c):h.data=c),a.extend(h,d),h}function c(b,c){a.forEach(b,function(a,d){this[d+c]=function(a){return void 0===a?b[d]:(b[d]=a,this)}},this)}function d(a){return function(){return a}}var e={login:"/users/sign_in.json",logout:"/users/sign_out.json",register:"/users.json",sendResetPasswordInstructions:"/users/password.json",resetPassword:"/users/password.json"},f={login:"POST",logout:"DELETE",register:"POST",sendResetPasswordInstructions:"POST",resetPassword:"PUT"},g="user",h=function(a){return a.data};c.call(this,f,"Method"),c.call(this,e,"Path"),this.resourceName=function(a){return void 0===a?g:(g=a,this)},this.parse=function(a){return"function"!=typeof a?h:(h=a,this)},this.$get=["$q","$http","$rootScope",function(a,c,e){function f(a){return j._currentUser=a,a}function g(){f(null),j._promise=null}function i(a){return function(b){return e.$broadcast("devise:"+a,b),b}}var j={_currentUser:null,parse:h,_promise:null,reset:function(){g(),j.currentUser()},login:function(a,d){var e=arguments.length>0,g=j.isAuthenticated();return a=a||{},c(b("login",a,d)).then(j.parse).then(f).then(function(a){return e&&!g?i("new-session")(a):a}).then(i("login"))},logout:function(a){var e=d(j._currentUser);return c(b("logout",void 0,a)).then(g).then(e).then(i("logout"))},register:function(a,d){return a=a||{},c(b("register",a,d)).then(j.parse).then(f).then(i("new-registration"))},sendResetPasswordInstructions:function(a){return a=a||{},c(b("sendResetPasswordInstructions",a)).then(j.parse).then(i("send-reset-password-instructions-successfully"))},resetPassword:function(a){return a=a||{},c(b("resetPassword",a)).then(j.parse).then(f).then(i("reset-password-successfully"))},currentUser:function(){return j.isAuthenticated()?a.when(j._currentUser):(null===j._promise&&(j._promise=j.login()),j._promise)},isAuthenticated:function(){return!!j._currentUser}};return j}]})}(angular); \ No newline at end of file +!function(a){"use strict";var b=a.module("Devise",[]);b.provider("AuthIntercept",function(){var a=!1;this.interceptAuth=function(b){return a=!!b||void 0===b,this},this.$get=["$rootScope","$q",function(b,c){return{responseError:function(d){var e=d.config.interceptAuth;if(e=!!e||a&&void 0===e,e&&401===d.status){var f=c.defer();return b.$broadcast("devise:unauthorized",d,f),f.reject(d),f.promise}return c.reject(d)}}}]}).config(["$httpProvider",function(a){a.interceptors.push("AuthIntercept")}]),b.provider("Auth",function(){function b(b,c,d){var g={method:f[b].toLowerCase(),url:e[b]};return c&&(h?(g.data={},g.data[h]=c):g.data=c),a.extend(g,d),g}function c(b,c){a.forEach(b,function(a,d){this[d+c]=function(a){return void 0===a?b[d]:(b[d]=a,this)}},this)}function d(a){return function(){return a}}var e={login:"/users/sign_in.json",logout:"/users/sign_out.json",register:"/users.json",sendResetPasswordInstructions:"/users/password.json",resetPassword:"/users/password.json"},f={login:"POST",logout:"DELETE",register:"POST",sendResetPasswordInstructions:"POST",resetPassword:"PUT"},g="",h="user",i=function(a){return a.data};c.call(this,f,"Method"),c.call(this,e,"Path"),this.baseUrl=function(a){return void 0===a?g:(g=a,this)},this.resourceName=function(a){return void 0===a?h:(h=a,this)},this.parse=function(a){return"function"!=typeof a?i:(i=a,this)},this.$get=["$q","$http","$rootScope",function(a,c,e){function f(a){return j._currentUser=a,a}function g(){f(null),j._promise=null}function h(a){return function(b){return e.$broadcast("devise:"+a,b),b}}var j={_currentUser:null,parse:i,_promise:null,reset:function(){g(),j.currentUser()},login:function(a,d){var e=arguments.length>0,g=j.isAuthenticated();return a=a||{},c(b("login",a,d)).then(j.parse).then(f).then(function(a){return e&&!g?h("new-session")(a):a}).then(h("login"))},logout:function(a){var e=d(j._currentUser);return c(b("logout",void 0,a)).then(g).then(e).then(h("logout"))},register:function(a,d){return a=a||{},c(b("register",a,d)).then(j.parse).then(f).then(h("new-registration"))},sendResetPasswordInstructions:function(a){return a=a||{},c(b("sendResetPasswordInstructions",a)).then(j.parse).then(h("send-reset-password-instructions-successfully"))},resetPassword:function(a){return a=a||{},c(b("resetPassword",a)).then(j.parse).then(f).then(h("reset-password-successfully"))},currentUser:function(){return j.isAuthenticated()?a.when(j._currentUser):(null===j._promise&&(j._promise=j.login()),j._promise)},isAuthenticated:function(){return!!j._currentUser}};return j}]})}(angular); \ No newline at end of file diff --git a/lib/devise.js b/lib/devise.js index dafd1e4..9fe1c06 100644 --- a/lib/devise.js +++ b/lib/devise.js @@ -60,6 +60,11 @@ resetPassword: 'PUT' }; + /** + * The default host URL. + */ + var baseUrl = ''; + /** * Default devise resource_name is 'user', can be set to any string. * If it's falsey, it will not namespace the data. @@ -122,6 +127,15 @@ configure.call(this, methods, 'Method'); configure.call(this, paths, 'Path'); + // The baseUrl config function + this.baseUrl = function(value) { + if (value === undefined) { + return baseUrl; + } + baseUrl = value; + return this; + }; + // The resourceName config function this.resourceName = function(value) { if (value === undefined) {