This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathstormpath-sdk-angularjs.min.js
More file actions
9 lines (9 loc) · 22.6 KB
/
Copy pathstormpath-sdk-angularjs.min.js
File metadata and controls
9 lines (9 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
/**
* stormpath-sdk-angularjs
* Copyright Stormpath, Inc. 2016
*
* @version v1.1.1-dev-2016-10-31
* @link https://github.com/stormpath/stormpath-sdk-angularjs
* @license Apache-2.0
*/
"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="stormpath"),function(a,b,c){"use strict";b.module("stormpath",["stormpath.CONFIG","stormpath.auth","stormpath.userService","stormpath.viewModelService","stormpath.socialLogin","stormpath.facebookLogin","stormpath.googleLogin"]).factory("SpAuthInterceptor",[function(){function a(){}return a.prototype.request=function(a){return a.withCredentials=!0,a},new a}]).factory("StormpathAgentInterceptor",["$window",function(a){function c(b){var c=a.document.createElement("a");return c.href=b,c}function d(){}return d.prototype.request=function(d){var e=c(d.url),f=a.location;return e.host===f.host&&(d.headers["X-Stormpath-Agent"]="stormpath-sdk-angularjs/1.1.1 angularjs/"+b.version.full),d},new d}]).config(["$httpProvider",function(a){a.interceptors.push("SpAuthInterceptor"),a.interceptors.push("StormpathAgentInterceptor")}]).provider("$stormpath",[function(){this.$get=["$user","$injector","STORMPATH_CONFIG","$rootScope","$location",function(a,b,d,e,f){function g(){var a=new m;return this.encodeUrlForm=a.encode.bind(a),b.has("$state")&&(n=b.get("$state")),b.has("$route")&&(o=b.get("$route")),this}function h(a,b){e.$broadcast(d.STATE_CHANGE_UNAUTHENTICATED,a,b)}function i(a,b){e.$broadcast(d.STATE_CHANGE_UNAUTHORIZED,a,b)}function j(b,c){var d=b;if(d&&d.authorize&&d.authorize.group)return a.currentUser.inGroup(d.authorize.group);if(c){var e=c.filter(function(b){return a.currentUser.inGroup(b)});return e.length>0}return console.error("Unknown authorize configuration for spStateConfig",b),!1}function k(a){e.$broadcast(d.ROUTE_CHANGE_UNAUTHENTICATED,a)}function l(a){e.$broadcast(d.ROUTE_CHANGE_UNAUTHORIZED,a)}function m(){return this.delimiter="&",this.arrayPrefixGenerators={brackets:function(a){return a+"[]"},indices:function(a,b){return a+"["+b+"]"},repeat:function(a){return a}},this}var n,o;return g.prototype.stateChangeInterceptor=function(b){e.$on("$stateChangeStart",function(d,e,f){var g=e.sp||{},k=e.data&&e.data.authorities?e.data.authorities:c;(g.authenticate||g.authorize||k&&k.length)&&!a.currentUser?(d.preventDefault(),a.get().then(function(){g.authorize||k&&k.length?j(g,k)?n.go(e.name,f):i(e,f):n.go(e.name,f)},function(){h(e,f)})):g.waitForUser&&null===a.currentUser?(d.preventDefault(),a.get()["finally"](function(){n.go(e.name,f)})):a.currentUser&&(g.authorize||k&&k.length)?j(g,k)||(d.preventDefault(),i(e,f)):e.name===b.loginState&&a.currentUser!==!1&&(d.preventDefault(),a.get()["finally"](function(){a.currentUser&&a.currentUser.href?n.go(b.defaultPostLoginState):n.go(e.name,f)}))})},g.prototype.routeChangeInterceptor=function(b){function c(a){setTimeout(function(){a.$$route.originalPath===f.path()?o.reload():f.path(a)})}e.$on("$routeChangeStart",function(d,e){if(e.$$route){var f=e.$$route.sp||{};!f.authenticate&&!f.authorize||a.currentUser?f.waitForUser&&null===a.currentUser?(d.preventDefault(),a.get()["finally"](function(){c(e)})):a.currentUser&&f.authorize?j(f)||(d.preventDefault(),l(e)):e.$$route.originalPath===b.loginRoute&&a.currentUser&&a.currentUser.href&&(d.preventDefault(),c(b.defaultPostLoginRoute)):(d.preventDefault(),a.get().then(function(){f.authorize?j(f)?c(e):i(e):c(e)},function(){k(e)}))}})},g.prototype.uiRouter=function(a){var b=this;a="object"==typeof a?a:{},this.stateChangeInterceptor(a),a.loginState&&(b.unauthenticatedWather=e.$on(d.STATE_CHANGE_UNAUTHENTICATED,function(c,d,e){b.postLogin={toState:d,toParams:e},n.go(a.loginState)})),e.$on(d.AUTHENTICATION_SUCCESS_EVENT_NAME,function(){b.postLogin&&a.autoRedirect!==!1?n.go(b.postLogin.toState,b.postLogin.toParams).then(function(){b.postLogin=null}):a.defaultPostLoginState&&n.go(a.defaultPostLoginState)}),a.forbiddenState&&(b.forbiddenWatcher=e.$on(d.STATE_CHANGE_UNAUTHORIZED,function(){n.go(a.forbiddenState)}))},g.prototype.ngRouter=function(a){var b=this;a="object"==typeof a?a:{},this.routeChangeInterceptor(a),a.loginRoute&&(this.unauthenticatedWather=e.$on(d.ROUTE_CHANGE_UNAUTHENTICATED,function(c,d){b.postLogin={toRoute:d},f.path(a.loginRoute)})),e.$on(d.AUTHENTICATION_SUCCESS_EVENT_NAME,function(){b.postLogin&&a.autoRedirect!==!1?(f.path(b.postLogin.toRoute),b.postLogin=null):a.defaultPostLoginRoute&&f.path(a.defaultPostLoginRoute)}),a.forbiddenRoute&&(this.forbiddenWatcher=e.$on(d.ROUTE_CHANGE_UNAUTHORIZED,function(){f.path(a.forbiddenRoute)}))},g.prototype.regexAttrParser=function(a){var b;return b=a instanceof RegExp?a:a&&/^\/.+\/[gim]?$/.test(a)?new RegExp(a.split("/")[1],a.split("/")[2]):a},m.prototype.stringify=function(a,b,c){if(a instanceof Date?a=a.toISOString():null===a&&(a=""),"string"==typeof a||"number"==typeof a||"boolean"==typeof a)return[encodeURIComponent(b)+"="+encodeURIComponent(a)];var d=[];if("undefined"==typeof a)return d;for(var e=Object.keys(a),f=0,g=e.length;f<g;++f){var h=e[f];d=Array.isArray(a)?d.concat(this.stringify(a[h],c(b,h),c)):d.concat(this.stringify(a[h],b+"["+h+"]",c))}return d},m.prototype.encode=function(a,b){b=b||{};var c="undefined"==typeof b.delimiter?this.delimiter:b.delimiter,d=[];if("object"!=typeof a||null===a)return"";var e;e=b.arrayFormat in this.arrayPrefixGenerators?b.arrayFormat:"indices"in b?b.indices?"indices":"repeat":"indices";for(var f=this.arrayPrefixGenerators[e],g=Object.keys(a),h=0,i=g.length;h<i;++h){var j=g[h];d=d.concat(this.stringify(a[j],j,f))}return d.join(c)},new g}]}]).run(["$rootScope","$user","STORMPATH_CONFIG",function(a,b,c){a.user=b.currentUser||null,b.get()["finally"](function(){a.user=b.currentUser}),a.$on(c.GET_USER_EVENT,function(){a.user=b.currentUser}),a.$on(c.SESSION_END_EVENT,function(){a.user=b.currentUser})}]).directive("ifUser",["$user","$rootScope",function(a,b){return{link:function(a,c){b.$watch("user",function(a){a&&a.href?c.removeClass("ng-hide"):c.addClass("ng-hide")})}}}]).directive("ifNotUser",["$user","$rootScope",function(a,b){return{link:function(a,c){b.$watch("user",function(a){a&&a.href?c.addClass("ng-hide"):c.removeClass("ng-hide")})}}}]).directive("ifUserInGroup",["$user","$rootScope","$parse","$stormpath",function(a,b,c,d){return{link:function(e,f,g){function h(){var b=a.currentUser;b&&b.groupTest(i||j)?f.removeClass("ng-hide"):f.addClass("ng-hide")}var i,j=g.ifUserInGroup;j&&(e.$watch(c(j),function(a){i=d.regexAttrParser(a),h()}),b.$watch("user",function(){h()}))}}}]).directive("ifUserNotInGroup",["$user","$rootScope","$parse","$stormpath",function(a,b,c,d){return{link:function(e,f,g){function h(){var b=a.currentUser;b&&b.groupTest(i||j)?f.addClass("ng-hide"):f.removeClass("ng-hide")}var i,j=g.ifUserNotInGroup;j&&(e.$watch(c(j),function(a){i=d.regexAttrParser(a),h()}),b.$watch("user",function(){h()}))}}}]).directive("whileResolvingUser",["$user","$rootScope",function(a,b){return{link:function(c,d){b.$watch("user",function(){a.currentUser||a.currentUser===!1?d.addClass("ng-hide"):d.removeClass("ng-hide")})}}}]).directive("ifUserStateKnown",["$user","$rootScope",function(a,b){return{link:function(c,d){b.$watch("user",function(){a.currentUser||a.currentUser===!1?d.removeClass("ng-hide"):d.addClass("ng-hide")})}}}]).directive("ifUserStateUnknown",["$user","$rootScope",function(a,b){return{link:function(c,d){b.$watch("user",function(){null===a.currentUser?d.removeClass("ng-hide"):d.addClass("ng-hide")})}}}]).directive("spLogout",["$auth",function(a){return{link:function(b,c){c.on("click",function(){a.endSession()})}}}]),b.module("stormpath.auth",["stormpath.CONFIG"]).config(["$injector","STORMPATH_CONFIG",function(a,b){var c={$get:["$http","$user","$rootScope","$spFormEncoder","$q","$spErrorTransformer",function(a,c,d,e,f,g){function h(){return this}function i(){d.$broadcast(b.SESSION_END_EVENT)}function j(a){d.$broadcast(b.AUTHENTICATION_SUCCESS_EVENT_NAME,a)}function k(a){d.$broadcast(b.AUTHENTICATION_FAILURE_EVENT_NAME,a)}return h.prototype.authenticate=function(d){function h(a){c.get(!0).then(function(){j(a)})}function i(a){return k(a),f.reject(g.transformError(a))}return a(e.formPost({url:b.getUrl("AUTHENTICATION_ENDPOINT"),method:"POST",headers:{Accept:"application/json"},withCredentials:!0,data:d})).then(h,i)},h.prototype.endSession=function(){var c=a.post(b.getUrl("DESTROY_SESSION_ENDPOINT"),null,{headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"}});return c.then(function(){i()},function(a){console.error("logout error",a)}),c},new h}]};a.get("$provide").provider(b.AUTH_SERVICE_NAME,c)}]),b.module("stormpath.CONFIG",[]).constant("STORMPATH_CONFIG",function(){var a={AUTHENTICATION_SUCCESS_EVENT_NAME:"$authenticated",AUTHENTICATION_FAILURE_EVENT_NAME:"$authenticationFailure",AUTH_SERVICE_NAME:"$auth",SOCIAL_LOGIN_SERVICE_NAME:"$socialLogin",AUTHENTICATION_ENDPOINT:"/login",CURRENT_USER_URI:"/me",DESTROY_SESSION_ENDPOINT:"/logout",EMAIL_VERIFICATION_ENDPOINT:"/verify",ENDPOINT_PREFIX:"",FORM_CONTENT_TYPE:"application/x-www-form-urlencoded",GET_USER_EVENT:"$currentUser",NOT_LOGGED_IN_EVENT:"$notLoggedin",FORGOT_PASSWORD_ENDPOINT:"/forgot",CHANGE_PASSWORD_ENDPOINT:"/change",SESSION_END_EVENT:"$sessionEnd",STATE_CHANGE_UNAUTHENTICATED:"$stateChangeUnauthenticated",STATE_CHANGE_UNAUTHORIZED:"$stateChangeUnauthorized",ROUTE_CHANGE_UNAUTHENTICATED:"$routeChangeUnauthenticated",ROUTE_CHANGE_UNAUTHORIZED:"$routeChangeUnauthorized",REGISTER_URI:"/register",REGISTERED_EVENT_NAME:"$registered"};return a.getUrl=function(a){return this.ENDPOINT_PREFIX+this[a]},a}()),b.module("stormpath").controller("SpEmailVerificationCtrl",["$scope","$location","$user",function(a,b,c){a.showVerificationError=!1,a.verifying=!1,a.reVerificationSent=!1,a.needsReVerification=!1,a.resendFailed=!1,a.formModel={username:""},b.search().sptoken?(a.verifying=!0,c.verify(b.search().sptoken).then(function(){a.verified=!0})["catch"](function(){a.needsReVerification=!0,a.showVerificationError=!0})["finally"](function(){a.verifying=!1})):(a.needsReVerification=!0,a.showVerificationError=!0),a.submit=function(){a.posting=!0,a.resendFailed=!1,a.showVerificationError=!1,c.resendVerificationEmail({login:a.formModel.username}).then(function(){a.reVerificationSent=!0})["catch"](function(){a.resendFailed=!0})["finally"](function(){a.posting=!1})}}]).directive("spEmailVerification",function(){return{templateUrl:function(a,b){return b.templateUrl||"spEmailVerification.tpl.html"},controller:"SpEmailVerificationCtrl"}}),b.module("stormpath").provider("$spErrorTransformer",[function(){this.$get=[function(){function a(){}return a.prototype.transformError=function(a){var b=null;a.data&&(b=a.data.message||a.data.error),b||(b="An error occured when communicating with the server.");var c=new Error(b);return c.httpResponse=a,c.statusCode=a.status,c},new a}]}]),b.module("stormpath").provider("$spFormEncoder",[function(){this.$get=["STORMPATH_CONFIG",function(a){function b(){var a=new c;return this.encodeUrlForm=a.encode.bind(a),this}function c(){return this.delimiter="&",this.arrayPrefixGenerators={brackets:function(a){return a+"[]"},indices:function(a,b){return a+"["+b+"]"},repeat:function(a){return a}},this}return b.prototype.formPost=function(b){if("application/x-www-form-urlencoded"===a.FORM_CONTENT_TYPE){var c=b.headers?b.headers:b.headers={};c["Content-Type"]=a.FORM_CONTENT_TYPE,b.data=this.encodeUrlForm(b.data)}return b},c.prototype.stringify=function(a,b,c){if(a instanceof Date?a=a.toISOString():null===a&&(a=""),"string"==typeof a||"number"==typeof a||"boolean"==typeof a)return[encodeURIComponent(b)+"="+encodeURIComponent(a)];var d=[];if("undefined"==typeof a)return d;for(var e=Object.keys(a),f=0,g=e.length;f<g;++f){var h=e[f];d=Array.isArray(a)?d.concat(this.stringify(a[h],c(b,h),c)):d.concat(this.stringify(a[h],b+"["+h+"]",c))}return d},c.prototype.encode=function(a,b){b=b||{};var c="undefined"==typeof b.delimiter?this.delimiter:b.delimiter,d=[];if("object"!=typeof a||null===a)return"";var e;e=b.arrayFormat in this.arrayPrefixGenerators?b.arrayFormat:"indices"in b?b.indices?"indices":"repeat":"indices";for(var f=this.arrayPrefixGenerators[e],g=Object.keys(a),h=0,i=g.length;h<i;++h){var j=g[h];d=d.concat(this.stringify(a[j],j,f))}return d.join(c)},new b}]}]),b.module("stormpath").controller("SpLoginFormCtrl",["$scope","$auth","$viewModel",function(a,b,c){a.viewModel=null,c.getLoginModel().then(function(b){var c=["facebook","google"];b.accountStores=b.accountStores.filter(function(a){var b=a.provider.providerId;return c.indexOf(b)>-1}),a.viewModel=b})["catch"](function(a){throw new Error("Could not load login view model from back-end: "+a.message)}),a.formModel={},a.posting=!1,a.submit=function(){a.posting=!0,a.error=null,b.authenticate(a.formModel)["catch"](function(b){a.posting=!1,a.error=b.message})}}]).directive("spLoginForm",function(){return{templateUrl:function(a,b){return b.templateUrl||"spLoginForm.tpl.html"},controller:"SpLoginFormCtrl"}}),b.module("stormpath").controller("SpPasswordResetRequestCtrl",["$scope","$user",function(a,b){a.sent=!1,a.posting=!1,a.formModel={username:""},a.error=null,a.submit=function(){a.posting=!0,a.error=null,b.passwordResetRequest({email:a.formModel.email}).then(function(){a.sent=!0})["catch"](function(b){a.error=b.message})["finally"](function(){a.posting=!1})}}]).controller("SpPasswordResetCtrl",["$scope","$location","$user",function(a,b,c){var d=b.search().sptoken;a.showVerificationError=!1,a.verifying=!1,a.verified=!1,a.posting=!1,a.reset=!1,a.error=null,a.resendFailed=!1,a.formModel={password:"",confirmPassword:""},"string"==typeof d?(a.verifying=!0,c.verifyPasswordResetToken(d).then(function(){a.verified=!0})["catch"](function(){a.showVerificationError=!0})["finally"](function(){a.verifying=!1})):a.showVerificationError=!0,a.submit=function(){return a.formModel.password!==a.formModel.confirmPassword?void(a.error="Passwords do not match"):(a.posting=!0,a.error=null,a.showVerificationError=!1,void c.resetPassword(d,{password:a.formModel.password}).then(function(){a.reset=!0})["catch"](function(b){a.error=b.message})["finally"](function(){a.posting=!1}))}}]).directive("spPasswordResetRequestForm",function(){return{templateUrl:function(a,b){return b.templateUrl||"spPasswordResetRequestForm.tpl.html"},controller:"SpPasswordResetRequestCtrl"}}).directive("spPasswordResetForm",function(){return{templateUrl:function(a,b){return b.templateUrl||"spPasswordResetForm.tpl.html"},controller:"SpPasswordResetCtrl"}}),b.module("stormpath").controller("SpRegistrationFormCtrl",["$scope","$user","$auth","$location","$viewModel","$injector",function(a,b,c,d,e,f){a.formModel="object"==typeof a.formModel?a.formModel:{},a.created=!1,a.enabled=!1,a.creating=!1,a.authenticating=!1,a.viewModel=null,e.getRegisterModel().then(function(b){var c=["facebook","google"];b.accountStores=b.accountStores.filter(function(a){var b=a.provider.providerId;return c.indexOf(b)>-1}),a.viewModel=b})["catch"](function(a){throw new Error("Could not load login view model from back-end: "+a.message)}),a.submit=function(){a.creating=!0,a.error=null,b.create(a.formModel).then(function(b){a.created=!0,a.enabled="ENABLED"===b.status,a.enabled&&a.autoLogin?(a.authenticating=!0,c.authenticate({username:a.formModel.email,password:a.formModel.password}).then(function(){var b=f.has("$state")?f.get("$state"):null;a.postLoginState&&b?b.go(a.postLoginState):a.postLoginPath&&d.path(a.postLoginPath)})["catch"](function(b){a.error=b.message})["finally"](function(){a.authenticating=!1,a.creating=!1})):a.creating=!1})["catch"](function(b){a.creating=!1,a.error=b.message})}}]).directive("spRegistrationForm",function(){return{templateUrl:function(a,b){return b.templateUrl||"spRegistrationForm.tpl.html"},controller:"SpRegistrationFormCtrl",link:function(a,b,c){a.autoLogin="true"===c.autoLogin,a.postLoginPath=c.postLoginPath||"",a.postLoginState=c.postLoginState||""}}}),function(){function c(a,b){switch(b.status){case"connected":a.resolve({providerData:{providerId:"facebook",accessToken:b.authResponse.accessToken}});break;case"not_authorized":a.reject(new Error("Please log into this app"));break;default:a.reject(new Error("Please log into Facebook."))}}function d(a,b){this.name="Facebook",this.clientId=null,this.$q=a,this.$spJsLoader=b}d.prototype.init=function(){var b=this.clientId;a.fbAsyncInit=function(){FB.init({appId:b,status:!0,cookie:!0,xfbml:!0,version:"v2.4"})},a.FB?a.fbAsyncInit():this.$spJsLoader.load("facebook-jssdk","//connect.facebook.net/en_US/sdk.js")},d.prototype.login=function(a){var b=this.$q.defer();return FB.login(c.bind(null,b),a),b.promise},b.module("stormpath.facebookLogin",[]).provider("$facebookLogin",function(){this.$get=["$q","$spJsLoader",function(a,b){return new d(a,b)}]})}(),function(){function a(a,b){this.name="Google",this.clientId=null,this.googleAuth=null,this.$q=a,this.$spJsLoader=b}a.prototype.setGoogleAuth=function(a){this.googleAuth=a},a.prototype.init=function(a){var b=this.clientId,c=this.setGoogleAuth.bind(this);this.$spJsLoader.load("google-jssdk","//apis.google.com/js/api:client.js").then(function(){gapi.load("auth2",function(){var a=gapi.auth2.init({client_id:b,cookiepolicy:"single_host_origin"});c(a)})})},a.prototype.login=function(a){var b=this.$q.defer();return a=a||{},a.redirect_uri="postmessage",this.googleAuth.grantOfflineAccess(a).then(function(a){b.resolve({providerData:{providerId:"google",code:a.code}})},function(a){b.reject(a)}),b.promise},b.module("stormpath.googleLogin",[]).provider("$googleLogin",function(){this.$get=["$q","$spJsLoader",function(b,c){return new a(b,c)}]})}(),function(){function a(a,b,c,d){this.providersPromise=null,this.STORMPATH_CONFIG=a,this.$injector=b,this.$http=c,this.$q=d}b.module("stormpath.socialLogin",["stormpath.CONFIG"]).config(["$injector","STORMPATH_CONFIG",function(b,c){var d=["$http","$q","$injector",function(b,d,e){return new a(c,e,b,d)}];b.get("$provide").factory(c.SOCIAL_LOGIN_SERVICE_NAME,d)}]).factory("$spJsLoader",["$q",function(a){return{load:function(b,c,d){var e=a.defer(),f=document.getElementsByTagName("script")[0],g=document.createElement("script");return document.getElementById(b)?e.resolve():(g.id=b,g.src=c,g.innerHTML=d,g.onload=e.resolve,f.parentNode.insertBefore(g,f)),e.promise}}}]).directive("spSocialLogin",["$viewModel","$auth","$injector",function(a,b,c){return{link:function(a,d,e){var f,g=a.$parent;try{f=c.get("$"+e.spSocialLogin+"Login")}catch(h){return}f.clientId=e.spClientId,f.init(d),a.providerName=f.name,d.bind("click",function(){var a={scope:e.spScope};g.posting=!0,f.login(a).then(function(a){return b.authenticate(a)})["catch"](function(a){g.posting=!1,a.message?g.error=a.message:g.error="An error occured when communicating with server."})})}}}])}(),function(){function a(a){return"api_key: "+a+"\nauthorize: true"}function c(b,c){var d=a(c);b.load("linkedin-jssdk","//platform.linkedin.com/in.js",d)}function d(a,b){this.name="LinkedIn",this.clientId=null,this.$q=a,this.$spJsLoader=b}d.prototype.init=function(a){c(this.$spJsLoader,this.clientId)},d.prototype.login=function(a){var b=this.$q.defer();return IN.User.authorize(function(){b.resolve({providerData:{providerId:"linkedin",accessToken:IN.ENV.auth.oauth_token}})}),b.promise},b.module("stormpath.linkedinLogin",[]).provider("$linkedinLogin",function(){this.$get=["$q","$spJsLoader",function(a,b){return new d(a,b)}]})}(),b.module("stormpath.userService",["stormpath.CONFIG","stormpath.util"]).provider("$user",[function(){function a(a){var b=this;Object.keys(a).map(function(c){b[c]=a[c]})}a.prototype.inGroup=function(a){return this.groups.items.filter(function(b){return b.name===a}).length>0},a.prototype.matchesGroupExpression=function(a){return this.groups.items.filter(function(b){return a.test(b.name)}).length>0},a.prototype.groupTest=function(a){return!!(a instanceof RegExp&&this.matchesGroupExpression(a))||!!this.inGroup(a)},this.$get=["$q","$http","STORMPATH_CONFIG","$rootScope","$spFormEncoder","$spErrorTransformer","$verifyResponse",function(b,c,d,e,f,g,h){function i(){return this.cachedUserOp=null,this.currentUser=null,this}function j(a){e.$broadcast(d.REGISTERED_EVENT_NAME,a)}function k(a){e.$broadcast(d.GET_USER_EVENT,a)}function l(){e.$broadcast(d.NOT_LOGGED_IN_EVENT)}i.prototype.create=function(a){return c(f.formPost({url:d.getUrl("REGISTER_URI"),method:"POST",data:a})).then(function(a){var c=a.data.account||a.data;return j(c),b.resolve(c)},function(a){return b.reject(g.transformError(a))})},i.prototype.get=function(e){var f=b.defer(),g=this;return g.cachedUserOp?g.cachedUserOp.promise:null!==g.currentUser&&g.currentUser!==!1&&e!==!0?(f.resolve(g.currentUser),f.promise):(g.cachedUserOp=f,c.get(d.getUrl("CURRENT_USER_URI"),{withCredentials:!0}).then(function(b){var c=h(b);return c.valid?(g.cachedUserOp=null,g.currentUser=new a(b.data.account||b.data),k(g.currentUser),void f.resolve(g.currentUser)):(g.currentUser=!1,f.reject(c.error))},function(a){g.currentUser=!1,401===a.status&&l(),g.cachedUserOp=null,f.reject(a)}),f.promise)},i.prototype.resendVerificationEmail=function(a){return c({method:"POST",url:d.getUrl("EMAIL_VERIFICATION_ENDPOINT"),data:a})},i.prototype.verify=function(a){return c({url:d.getUrl("EMAIL_VERIFICATION_ENDPOINT")+"?sptoken="+a})},i.prototype.verifyPasswordResetToken=function(a){return c.get(d.getUrl("CHANGE_PASSWORD_ENDPOINT")+"?sptoken="+a)},i.prototype.passwordResetRequest=function(a){return c(f.formPost({method:"POST",url:d.getUrl("FORGOT_PASSWORD_ENDPOINT"),data:a}))["catch"](function(a){return b.reject(g.transformError(a))})},i.prototype.resetPassword=function(a,e){return e.sptoken=a,c(f.formPost({method:"POST",url:d.getUrl("CHANGE_PASSWORD_ENDPOINT"),data:e}))["catch"](function(a){return b.reject(g.transformError(a))})};var m=new i;return e.$on(d.SESSION_END_EVENT,function(){m.currentUser=!1}),m}]}]),b.module("stormpath.util",[]).factory("$verifyResponse",function(){return function(a){if(!a||"function"!=typeof a.headers)return{valid:!1,error:{message:"Invalid response object format"}};var b=a.headers("Content-Type");return b.startsWith("application/json")?{valid:!0}:{valid:!1,error:{message:"Incorrect current user API endpoint response content type: "+b}}}}),function(){function a(a,b,c){this.$http=a,this.$verifyResponse=b,this.STORMPATH_CONFIG=c}a.prototype.getLoginModel=function(){var a=this;return this.$http.get(this.STORMPATH_CONFIG.getUrl("AUTHENTICATION_ENDPOINT"),{headers:{Accept:"application/json"}}).then(function(b){var c=a.$verifyResponse(b);if(!c.valid)throw c.error;return b.data})},a.prototype.getRegisterModel=function(){var a=this;return this.$http.get(this.STORMPATH_CONFIG.getUrl("REGISTER_URI"),{headers:{Accept:"application/json"}}).then(function(b){var c=a.$verifyResponse(b);if(!c.valid)throw c.error;return b.data})},b.module("stormpath.viewModelService",["stormpath.util"]).provider("$viewModel",function(){this.$get=["$http","$verifyResponse","STORMPATH_CONFIG",function(b,c,d){return new a(b,c,d)}]})}()}(window,window.angular);