This repository has been archived by the owner on Oct 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbzz.angular.min.js
1 lines (1 loc) · 4.64 KB
/
bzz.angular.min.js
1
(function(){"use strict";var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}};b={googleClientId:null,googleApiKey:null,googleScopes:"https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",bzzApiUrl:"http://localhost:2368/",redirectWhenLogin:"/",loginPage:"/login"},a=function(){function a(a,b,d,e,f,g){this.options=a,this.http=b,this.rootScope=d,this.location=e,this.route=f,this.GooglePlus=g,this.googleLogin=c(this.googleLogin,this),this.baseLen=this._getBaseLen(),this.redirectUrl=this._getOption("redirectWhenLogin"),this.bindEvents()}return a.prototype._getBaseLen=function(){var a;return a=this.location.absUrl().length-this.location.url().length,""===this.location.url()?a-1:a},a.prototype._getOption=function(a){return null!=this.options?this.options[a]:b[a]},a.prototype._getRelativeUrl=function(a){return null!=a?a.substring(this.baseLen):a},a.prototype.bindEvents=function(){return this.rootScope.$on("unauthorizedRequest",function(a){return function(b,c){return a.signOut(c)}}(this)),this.rootScope.$on("$locationChangeStart",function(a){return function(b,c,d,e){var f;return f=a._getOption("loginPage"),a._getRelativeUrl(c)===f&&a._getRelativeUrl(d)!==f&&(a.redirectUrl=a._getRelativeUrl(d)),a.rootScope.$broadcast("$locationChangeSuccess",c,d,e)}}(this)),this.rootScope.$on("$locationChangeSuccess",function(a){return function(b,c,d,e){return a.route.current.requiresAuthentication?a.checkAuthentication("function"==typeof e?e:void 0):"function"==typeof e?e():void 0}}(this))},a.prototype.getAuthMe=function(){var a;return a="/auth/me/",this.http.get(this._getOption("bzzApiUrl")+a)},a.prototype.checkAuthentication=function(a){return this.getAuthMe().success(function(b){return function(c){return c.authenticated?(b.isAuthenticated=c.authenticated,b.userData=c.userData,b.location.url()===b._getOption("loginPage")&&b.location.url(b.redirectUrl),a?a():void 0):b.signOut(a)}}(this)).error(function(){return function(a){return console.log("Failed to check Authentication:",a)}}(this))},a.prototype._onSignedIn=function(){return this.isAuthenticated=!0,this.location.url(this.redirectUrl),this.rootScope.$broadcast("bzzUserSignedIn")},a.prototype.setSignIn=function(a,b){var c;return c="/auth/signin/",this.http.post(this._getOption("bzzApiUrl")+c,{provider:a,access_token:b})},a.prototype.signIn=function(a,b,c){return this.setSignIn(a,b.access_token).then(function(a){return function(b){return b.data.authenticated?(a._onSignedIn(),c?c():void 0):a.signOut(c)}}(this),function(a){return function(){return a.signOut(c)}}(this))},a.prototype._onSignedOut=function(){return this.isAuthenticated=!1,this.userData=null,this.location.url(this._getOption("loginPage")),this.rootScope.$broadcast("bzzUserSignedOut")},a.prototype.setSignOut=function(){var a;return a="/auth/signout/",this.http.post(this._getOption("bzzApiUrl")+a,"")},a.prototype.signOut=function(a){return this.setSignOut().success(function(b){return function(c){return c.loggedOut&&(b._onSignedOut(),a)?a():void 0}}(this)).error(function(){return function(a){return console.log("Failed to signOut: ",a)}}(this))},a.prototype.googleLogin=function(a){return this.GooglePlus.login().then(function(b){return function(c){return b.signIn("google",c,a)}}(this),function(b){return function(){return b.signOut(a)}}(this))},a}(),angular.module("bzz.auth",["ngRoute","googleplus"]).provider("AuthService",["GooglePlusProvider",function(c){this.init=function(a){return this.options=angular.extend(b,a),this.initializeGooglePlus(this.options)},this.initializeGooglePlus=function(a){return c.init({clientId:a.googleClientId,apiKey:a.googleApiKey,scopes:a.googleScopes})},this.$get=["$http","$rootScope","$location","$route","GooglePlus",function(b,c,d,e,f){return new a(this.options,b,c,d,e,f)}]}])}).call(this),function(){"use strict";var a;a=function(){function a(a,b,c){this.scope=a,this.provider=b,this.AuthService=c}return a.prototype.login=function(){return"google"===this.provider?this.AuthService.googleLogin():console.log("Invalid provider")},a}(),angular.module("bzz.auth").directive("authButton",["AuthService",function(b){return{template:'<a href="javascript:;" class="{{ model.provider }}-login auth-button" ng-click="model.login()">\n<span class="icon"></span><span class="text">Entrar com {{ model.provider }}</span></a>',restrict:"E",transclude:!0,link:function(c,d,e){return c.model=new a(c,e.provider,b)}}}])}.call(this),function(){"use strict";angular.module("bzz.auth").factory("httpResponseInterceptor",["$q","$rootScope",function(a,b){var c,d,e;return c=function(c){return 401===c.status&&b.$broadcast("unauthorizedRequest"),a.reject(c)},d=function(a){return a},e=function(a){return a.then(d,c)}}])}.call(this);