UNPKG

@incdevco/framework

Version:
1 lines 417 kB
{"filter":false,"title":"user.js","tooltip":"/dist/angular/modules/user.js","undoManager":{"mark":12,"position":12,"stack":[[{"start":{"row":1,"column":0},"end":{"row":295,"column":48},"action":"remove","lines":["<<<<<<< HEAD","/* global angular localStorage */","","angular.module('user', [])",".controller('UserDirectiveController', ["," 'Auth',"," '$scope',"," function (Auth, $scope) {"," "," var crtl = this;"," "," this.authenticating = false;"," "," this.failure = null;"," "," this.google = null;"," "," this.successful = null;"," "," this.user = null;"," "," this.login = function () {"," "," console.log('login');"," "," Auth.authenticate();"," "," };"," "," this.logout = function () {"," "," Auth.deauthenticate();"," "," };"," "," $scope.$on('attempting-authentication', function (event, promise) {"," "," crtl.authenticating = true;"," "," promise"," .then(function (result) {"," "," crtl.authenticating = false;"," "," crtl.successful = result;"," "," })"," .catch(function (exception) {"," "," crtl.authenticating = false;"," "," crtl.failure = exception;"," "," });"," "," });"," "," $scope.$on('deauthenticated', function() {"," "," crtl.google = null;"," "," crtl.user = null;"," "," });"," "," $scope.$on('user.facebook', function (event, facebook) {"," "," console.log('UserController', 'user.facebook', facebook);"," "," crtl.facebook = facebook;"," "," if (!crtl.user) {"," "," crtl.user = {"," name: facebook.name"," };"," "," }"," "," });"," "," $scope.$on('user.google', function (event, google) {"," "," console.log('UserController', 'user.google', google);"," "," crtl.google = google;"," "," if (!crtl.user) {"," "," crtl.user = {"," name: google.getBasicProfile().getName(),"," photo_url: google.getBasicProfile().getImageUrl(),"," role: 'Guest'"," };"," "," }"," "," });"," "," $scope.$on('user', function (event, user) {"," "," console.log('UserController', 'user', user);"," "," crtl.user = user;"," "," });","=======","/* global angular FB gapi localStorage moment */","","angular.module('user', [])",".controller('UserAuthenticationController', ["," 'User',"," '$mdDialog',"," '$scope',"," function (User, $mdDialog, $scope) {"," "," this.enabled = {};"," "," this.cancel = function () {"," "," $mdDialog.cancel();"," "," };"," "," // listen to providers"," // first to authenticate is winner"," "," $scope.$on('facebook:authenticated', function () {"," "," $mdDialog.hide();"," "," });"," "," $scope.$on('google:authenticated', function () {"," "," $mdDialog.hide();"," "," });"," "," this.enabled = User.getEnabledProviders();"," "," }","])",".controller('UserDirectiveController', ["," 'User',"," '$log',"," '$mdDialog',"," '$mdToast',"," '$scope',"," '$window',"," function (User, $log, $mdDialog, $mdToast, $scope, $window) {"," "," var crtl = this;"," "," this.authenticated = false;"," "," this.processing = false;"," "," this.user = null;"," "," this.loginDialog = function ($event) {"," "," console.log('loginDialog');"," "," crtl.processing = true;"," "," User.authenticate()"," .catch(function (exception) {"," "," $log.error(exception);"," "," })"," .finally(function () {"," "," crtl.processing = false;"," "," });"," "," };"," "," this.logoutDialog = function ($event) {"," "," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserLogoutController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/logout.html'"," })"," .finally(function () {"," "," $window.location.href = '/';"," "," });"," "," };"," "," this.registerDialog = function ($event) {"," "," this.loginDialog($event);"," /*"," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserRegisterController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/register.html'"," });"," */"," };"," "," this.settingsDialog = function ($event) {"," "," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserSettingsController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/settings.html'"," });"," "," };"," "," $scope.$on('authenticated', function () {"," "," $log.debug('UserDirectiveController', 'authenticated');"," "," crtl.authenticated = true;"," "," });"," "," $scope.$on('deauthenticated', function () {"," "," crtl.authenticated = false;"," "," crtl.processing = false;"," "," crtl.user = null;"," "," });"," "," $scope.$on('user', function ($event, user) {"," "," $log.debug('UserDirectiveController', 'user');"," "," crtl.user = user;"," "," crtl.authenticated = true;"," "," });"," "," }","])",".controller('UserLoginController', ["," function () {"," "," "," "," }","])",".controller('UserLogoutController', ["," 'User',"," '$mdDialog',"," function (User, $mdDialog) {"," "," this.enabled = User.getEnabledProviders();"," "," this.done = function () {"," "," $mdDialog.hide();"," "," };"," "," User.logout();"," "," }","])",".controller('UserRegisterController', ["," function () {"," "," "," "," }","])",".controller('UserSettingsController', ["," function () {"," "," ",">>>>>>> 439273e2fb408009e1179f947ae3da7902ce6d12"],"id":3},{"start":{"row":1,"column":0},"end":{"row":187,"column":4},"action":"insert","lines":["/* global angular FB gapi localStorage moment */","","angular.module('user', [])",".controller('UserAuthenticationController', ["," 'User',"," '$mdDialog',"," '$scope',"," function (User, $mdDialog, $scope) {"," "," this.enabled = {};"," "," this.cancel = function () {"," "," $mdDialog.cancel();"," "," };"," "," // listen to providers"," // first to authenticate is winner"," "," $scope.$on('facebook:authenticated', function () {"," "," $mdDialog.hide();"," "," });"," "," $scope.$on('google:authenticated', function () {"," "," $mdDialog.hide();"," "," });"," "," this.enabled = User.getEnabledProviders();"," "," }","])",".controller('UserDirectiveController', ["," 'User',"," '$log',"," '$mdDialog',"," '$mdToast',"," '$scope',"," '$window',"," function (User, $log, $mdDialog, $mdToast, $scope, $window) {"," "," var crtl = this;"," "," this.authenticated = false;"," "," this.processing = false;"," "," this.user = null;"," "," this.loginDialog = function ($event) {"," "," console.log('loginDialog');"," "," crtl.processing = true;"," "," User.authenticate()"," .catch(function (exception) {"," "," $log.error(exception);"," "," })"," .finally(function () {"," "," crtl.processing = false;"," "," });"," "," };"," "," this.logoutDialog = function ($event) {"," "," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserLogoutController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/logout.html'"," })"," .finally(function () {"," "," $window.location.href = '/';"," "," });"," "," };"," "," this.registerDialog = function ($event) {"," "," this.loginDialog($event);"," /*"," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserRegisterController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/register.html'"," });"," */"," };"," "," this.settingsDialog = function ($event) {"," "," $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserSettingsController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," targetEvent: $event,"," templateUrl: 'user/templates/settings.html'"," });"," "," };"," "," $scope.$on('authenticated', function () {"," "," $log.debug('UserDirectiveController', 'authenticated');"," "," crtl.authenticated = true;"," "," });"," "," $scope.$on('deauthenticated', function () {"," "," crtl.authenticated = false;"," "," crtl.processing = false;"," "," crtl.user = null;"," "," });"," "," $scope.$on('user', function ($event, user) {"," "," $log.debug('UserDirectiveController', 'user');"," "," crtl.user = user;"," "," crtl.authenticated = true;"," "," });"," "," }","])",".controller('UserLoginController', ["," function () {"," "," "," "," }","])",".controller('UserLogoutController', ["," 'User',"," '$mdDialog',"," function (User, $mdDialog) {"," "," this.enabled = User.getEnabledProviders();"," "," this.done = function () {"," "," $mdDialog.hide();"," "," };"," "," User.logout();"," "," }","])",".controller('UserRegisterController', ["," function () {"," "," "," "," }","])",".controller('UserSettingsController', ["," function () {"," "," "]}],[{"start":{"row":202,"column":0},"end":{"row":1036,"column":48},"action":"remove","lines":["<<<<<<< HEAD"," "," }","])",".factory('User', ["," 'API',"," 'Auth',"," '$q',"," '$rootScope',"," function (API, Auth, $q, $rootScope) {"," "," var facebookKey = 'graph.facebook.com';"," "," var googleKey = 'accounts.google.com';"," "," var providerData = {}, user;"," "," var identity;"," "," var userKey = 'user';"," "," var service = {"," get: function () {"," "," return API({"," auth: true,"," method: 'GET',"," url: '/authenticated'"," })"," .then(function (result) {"," "," if (result) {"," "," user = result;"," "," $rootScope.$broadcast('user', user);"," "," }"," "," return result;","======="," "," }","])",".directive('userAuthenticationEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/email.html'"," };"," "," }","])",".directive('userAuthenticationFacebook', ["," 'UserFacebook',"," '$log',"," '$mdToast',"," function (Facebook, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfFacebook = function () {"," "," Facebook.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Facebook.render();"," "," Facebook.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug('Facebook.is', exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/facebook.html'"," };"," "," }","])",".directive('userAuthenticationGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/github.html'"," };"," "," }","])",".directive('userAuthenticationGoogle', ["," 'UserGoogle',"," '$log',"," '$mdToast',"," function (Google, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfGoogle = function () {"," "," Google.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Google.render();"," "," Google.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug('Google.is', exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/google.html'"," };"," "," }","])",".directive('userAuthenticationLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/linkedin.html'"," };"," "," }","])",".directive('userAuthenticationTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/twitter.html'"," };"," "," }","])",".directive('userIntegrationEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/email.html'"," };"," "," }","])",".directive('userIntegrationFacebook', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/facebook.html'"," };"," "," }","])",".directive('userIntegrationGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/github.html'"," };"," "," }","])",".directive('userIntegrationGoogle', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/google.html'"," };"," "," }","])",".directive('userIntegrationLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/linkedin.html'"," };"," "," }","])",".directive('userIntegrationTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/twitter.html'"," };"," "," }","])",".directive('userLogoutEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/email.html'"," };"," "," }","])",".directive('userLogoutFacebook', ["," 'UserFacebook',"," '$log',"," '$mdToast',"," function (Facebook, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.$on('facebook:deauthenticated', function () {"," "," $scope.user = false;"," "," });"," "," Facebook.render();"," "," Facebook.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug(exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/facebook.html'"," };"," "," }","])",".directive('userLogoutGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/github.html'"," };"," "," }","])",".directive('userLogoutGoogle', ["," 'UserGoogle',"," '$log',"," '$mdToast',"," function (Google, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfGoogle = function () {"," "," Google.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Google.render();"," "," Google.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug(exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/google.html'"," };"," "," }","])",".directive('userLogoutLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/linkedin.html'"," };"," "," }","])",".directive('userLogoutTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/twitter.html'"," };"," "," }","])",".provider('User', ["," function () {"," "," var enabled = {"," email: false,"," facebook: false,"," github: false,"," google: false,"," linkedin: false,"," twitter: false"," };"," "," this.enableEmail = function () {"," "," enabled.email = true;"," "," };"," "," this.enableFacebook = function () {"," "," enabled.facebook = true;"," "," };"," "," this.enableGoogle = function () {"," "," enabled.google = true;"," "," };"," "," this.$get = ["," 'COGNITO_IDENTITY_POOL_ID',"," 'COGNITO_IDENTITY_POOL_REGION',"," 'CognitoIdentity',"," 'UserFacebook',"," 'UserGoogle',"," '$injector',"," '$log',"," '$mdDialog',"," '$q',"," '$rootScope',"," '$timeout',"," function (identityPoolId,"," identityPoolRegion,"," CognitoIdentity,"," Facebook, "," Google, "," $injector,"," $log,"," $mdDialog, "," $q,"," $rootScope,"," $timeout) {"," "," var authentication,"," authenticateCalled = false,"," expiration, "," identity, "," logins = {}, "," user;"," "," authentication = $q.defer();"," "," function login(logins) {"," "," $log.debug('login', JSON.stringify(logins, null, 2));"," "," var count = Object.keys(logins).length;"," "," $log.debug('count', count);"," "," if (count) {"," "," return CognitoIdentity({"," IdentityId: null,"," IdentityPoolId: identityPoolId,"," Logins: logins,"," RoleSessionName: 'web-client'"," }, identityPoolRegion)"," .catch(function (exception) {"," "," if (exception.code === 'NotAuthorizedException') {"," "," if (identity) {"," "," logout();"," "," }"," "," }"," "," throw exception;"," "," })"," .then(function () {"," "," $rootScope.$broadcast('authenticated');"," "," });"," "," } else {"," "," return $q.resolve(false);"," "," }"," "," }"," "," function logout() {"," "," authentication = null;"," "," identity = null;"," "," expiration = null;"," "," logins = {};"," "," user = null;"," "," CognitoIdentity.clearCachedId();"," "," $rootScope.$broadcast('deauthenticated');"," "," $log.debug('User.logout', identity);"," "," }"," "," $rootScope.$on('aws.credentials', function () {"," "," var API = $injector.get('API');"," "," API({ "," method: 'GET',"," sign: true,"," url: '/authenticated'"," })"," .then(function (result) {"," "," if (result) {"," "," return result;"," "," } else if (user) {"," "," return API({"," data: user,"," method: 'POST',"," sign: true,"," url: '/authenticated'"," });"," "," }"," "," })"," .then(function (result) {"," "," user = result;"," "," $rootScope.$broadcast('user', user);"," "," })"," .catch(function (exception) {"," "," $log.error(exception);"," "," });"," "," });"," "," $rootScope.$on('cognito.identity', function ($event, result) {"," "," expiration = moment(result.expireTime);"," "," identity = result;"," "," if (user && !user.id) {"," "," user.id = result.identityId;"," "," }"," "," });"," "," $rootScope.$on('facebook:authenticated', function ($event, authResponse) {"," "," logins['graph.facebook.com'] = authResponse.accessToken;"," "," $log.debug('facebook:authenticated', logins);"," "," if (authentication) {"," "," $log.debug('facebook:authenticated', 'resolving authentication');"," "," authentication.resolve('facebook');"," "," }"," "," Facebook.getUser()"," .then(function (result) {"," "," user = {"," email_address: result.email,"," facebook: {"," id: result.id"," },"," full_name: result.name,"," name: result.name,"," photo_url: result.picture.data.url"," };"," "," if (!authenticateCalled) {"," "," login(logins);"," "," }"," "," })"," .catch(function (exception) {"," "," $log.debug(exception);"," "," });"," "," });"," "," $rootScope.$on('facebook:deauthenticated', function () {"," "," delete logins['graph.facebook.com'];"," "," login(logins);"," "," });"," "," $rootScope.$on('google:authenticated', function ($event, authResponse) {"," "," logins['accounts.google.com'] = "," authResponse.id_token;"," "," $log.debug('google:authenticated', logins);"," "," if (authentication) {"," "," authentication.resolve('google');"," "," }"," "," Google.getUser()"," .then(function (result) {"," "," user = {"," email_address: result.getBasicProfile().getEmail(),"," first_name: result.getBasicProfile().getGivenName(),"," full_name: result.getBasicProfile().getName(),"," google: {"," id_token: result.getAuthResponse().id_token,"," granted_scopes: result.getGrantedScopes(),"," hosted_domain: result.getHostedDomain()"," },"," last_name: result.getBasicProfile().getFamilyName(),"," name: result.getBasicProfile().getName(),"," photo_url: result.getBasicProfile().getImageUrl()"," };"," "," if (!authenticateCalled) {"," "," login(logins);"," "," }"," "," })"," .catch(function (exception) {"," "," $log.debug(exception);"," "," });"," "," });"," "," $rootScope.$on('google:deauthenticated', function () {"," "," delete logins['accounts.google.com'];"," "," login(logins);"," "," });"," "," return {"," authenticate: function () {"," "," $log.debug('User.authenticate');"," "," authenticateCalled = true;"," "," // is the user already authenticated"," // then we have credentials"," "," if (identity && expiration.isAfter(moment())) {"," "," $log.debug('identity && expiration', identity, expiration);"," "," return $q.resolve(true);"," "," }"," "," // we don't have credentials"," // ask the providers without displaying dialog"," "," if (!authentication) {"," "," $log.debug('creatting new authentication');"," "," authentication = $q.defer();"," "," }"," "," $log.debug('before race');"," "," return $q.race(["," Facebook.authenticate(),"," Google.authenticate()"," ])"," .catch(function () {"," "," // we could not get credentials from providers"," // display user authentication dialog"," // should return login from provider"," "," return $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserAuthenticationController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," templateUrl: 'user/templates/authentication.html'"," });"," "," })"," .then(function () {"," "," $log.debug('after race');"," "," return authentication.promise;"," "," })"," .then(function () {"," "," // a provider has authed"," // at least one login is available"," // get credentials then resolve promise"," "," $log.debug('after authentication');"," "," return login(logins);"," "," })"," .finally(function () {"," "," authenticateCalled = false;"," "," });"," "," },"," getEnabledProviders: function () {"," "," return {"," email: (enabled.email) ? true : false,"," facebook: (enabled.facebook) ? true : false,"," github: (enabled.github) ? true : false,"," google: (enabled.google) ? true : false,"," linkedin: (enabled.linkedin) ? true : false,"," twitter: (enabled.twitter) ? true : false"," };"," "," },"," logout: function () {"," "," logout();"," "," }"," };"," "," }"," ];"," "," }","])",".provider('UserEmail', ["," function () {"," "," var enabled = false;"," "," this.enable = function (config) {"," "," enabled = true;"," "," };"," "," this.$get = ["," '$q',"," '$rootScope',"," '$window',"," function ($q, $rootScope, $window) {"," "," var authenticated, authentication, ready;"," "," authentication = $q.defer();"," "," ready = $q.defer();"," "," function authed() {"," "," if (authentication.promise.$$state.status !== 0) {"," "," authentication = $q.defer();"," "," }"," "," authenticated = true;"," "," authentication.resolve(true);"," "," $rootScope.$broadcast('facebook:authenticated');"," "," }"," "," function deauthed() {"," "," if (authentication.promise.$$state.status !== 0) {"," "," authentication = $q.defer();"," "," }"," "," authenticated = false;",">>>>>>> 439273e2fb408009e1179f947ae3da7902ce6d12"],"id":4},{"start":{"row":202,"column":0},"end":{"row":994,"column":32},"action":"insert","lines":[" "," }","])",".directive('userAuthenticationEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/email.html'"," };"," "," }","])",".directive('userAuthenticationFacebook', ["," 'UserFacebook',"," '$log',"," '$mdToast',"," function (Facebook, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfFacebook = function () {"," "," Facebook.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Facebook.render();"," "," Facebook.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug('Facebook.is', exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/facebook.html'"," };"," "," }","])",".directive('userAuthenticationGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/github.html'"," };"," "," }","])",".directive('userAuthenticationGoogle', ["," 'UserGoogle',"," '$log',"," '$mdToast',"," function (Google, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfGoogle = function () {"," "," Google.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Google.render();"," "," Google.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug('Google.is', exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/google.html'"," };"," "," }","])",".directive('userAuthenticationLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/linkedin.html'"," };"," "," }","])",".directive('userAuthenticationTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/authentication/twitter.html'"," };"," "," }","])",".directive('userIntegrationEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/email.html'"," };"," "," }","])",".directive('userIntegrationFacebook', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/facebook.html'"," };"," "," }","])",".directive('userIntegrationGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/github.html'"," };"," "," }","])",".directive('userIntegrationGoogle', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/google.html'"," };"," "," }","])",".directive('userIntegrationLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/linkedin.html'"," };"," "," }","])",".directive('userIntegrationTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/integration/twitter.html'"," };"," "," }","])",".directive('userLogoutEmail', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/email.html'"," };"," "," }","])",".directive('userLogoutFacebook', ["," 'UserFacebook',"," '$log',"," '$mdToast',"," function (Facebook, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.$on('facebook:deauthenticated', function () {"," "," $scope.user = false;"," "," });"," "," Facebook.render();"," "," Facebook.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug(exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/facebook.html'"," };"," "," }","])",".directive('userLogoutGithub', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/github.html'"," };"," "," }","])",".directive('userLogoutGoogle', ["," 'UserGoogle',"," '$log',"," '$mdToast',"," function (Google, $log, $mdToast) {"," "," return {"," link: function ($scope) {"," "," $scope.logoutOfGoogle = function () {"," "," Google.logout()"," .then(function () {"," "," $scope.user = null;"," "," $mdToast.showSimple('Logged Out Of Google');"," "," }, function (exception) {"," "," $log.error(exception);"," "," $mdToast.showSimple('Sorry, there was an error.');"," "," });"," "," };"," "," Google.render();"," "," Google.is()"," .then(function (result) {"," "," $scope.user = result;"," "," }, function (exception) {"," "," $log.debug(exception);"," "," });"," "," },"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/google.html'"," };"," "," }","])",".directive('userLogoutLinkedin', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/linkedin.html'"," };"," "," }","])",".directive('userLogoutTwitter', ["," function () {"," "," return {"," replace: true,"," restrict: 'E',"," scope: true,"," templateUrl: 'user/templates/logout/twitter.html'"," };"," "," }","])",".provider('User', ["," function () {"," "," var enabled = {"," email: false,"," facebook: false,"," github: false,"," google: false,"," linkedin: false,"," twitter: false"," };"," "," this.enableEmail = function () {"," "," enabled.email = true;"," "," };"," "," this.enableFacebook = function () {"," "," enabled.facebook = true;"," "," };"," "," this.enableGoogle = function () {"," "," enabled.google = true;"," "," };"," "," this.$get = ["," 'COGNITO_IDENTITY_POOL_ID',"," 'COGNITO_IDENTITY_POOL_REGION',"," 'CognitoIdentity',"," 'UserFacebook',"," 'UserGoogle',"," '$injector',"," '$log',"," '$mdDialog',"," '$q',"," '$rootScope',"," '$timeout',"," function (identityPoolId,"," identityPoolRegion,"," CognitoIdentity,"," Facebook, "," Google, "," $injector,"," $log,"," $mdDialog, "," $q,"," $rootScope,"," $timeout) {"," "," var authentication,"," authenticateCalled = false,"," expiration, "," identity, "," logins = {}, "," user;"," "," authentication = $q.defer();"," "," function login(logins) {"," "," $log.debug('login', JSON.stringify(logins, null, 2));"," "," var count = Object.keys(logins).length;"," "," $log.debug('count', count);"," "," if (count) {"," "," return CognitoIdentity({"," IdentityId: null,"," IdentityPoolId: identityPoolId,"," Logins: logins,"," RoleSessionName: 'web-client'"," }, identityPoolRegion)"," .catch(function (exception) {"," "," if (exception.code === 'NotAuthorizedException') {"," "," if (identity) {"," "," logout();"," "," }"," "," }"," "," throw exception;"," "," })"," .then(function () {"," "," $rootScope.$broadcast('authenticated');"," "," });"," "," } else {"," "," return $q.resolve(false);"," "," }"," "," }"," "," function logout() {"," "," authentication = null;"," "," identity = null;"," "," expiration = null;"," "," logins = {};"," "," user = null;"," "," CognitoIdentity.clearCachedId();"," "," $rootScope.$broadcast('deauthenticated');"," "," $log.debug('User.logout', identity);"," "," }"," "," $rootScope.$on('aws.credentials', function () {"," "," var API = $injector.get('API');"," "," API({ "," method: 'GET',"," sign: true,"," url: '/authenticated'"," })"," .then(function (result) {"," "," if (result) {"," "," return result;"," "," } else if (user) {"," "," return API({"," data: user,"," method: 'POST',"," sign: true,"," url: '/authenticated'"," });"," "," }"," "," })"," .then(function (result) {"," "," user = result;"," "," $rootScope.$broadcast('user', user);"," "," })"," .catch(function (exception) {"," "," $log.error(exception);"," "," });"," "," });"," "," $rootScope.$on('cognito.identity', function ($event, result) {"," "," expiration = moment(result.expireTime);"," "," identity = result;"," "," if (user && !user.id) {"," "," user.id = result.identityId;"," "," }"," "," });"," "," $rootScope.$on('facebook:authenticated', function ($event, authResponse) {"," "," logins['graph.facebook.com'] = authResponse.accessToken;"," "," $log.debug('facebook:authenticated', logins);"," "," if (authentication) {"," "," $log.debug('facebook:authenticated', 'resolving authentication');"," "," authentication.resolve('facebook');"," "," }"," "," Facebook.getUser()"," .then(function (result) {"," "," user = {"," email_address: result.email,"," facebook: {"," id: result.id"," },"," full_name: result.name,"," name: result.name,"," photo_url: result.picture.data.url"," };"," "," if (!authenticateCalled) {"," "," login(logins);"," "," }"," "," })"," .catch(function (exception) {"," "," $log.debug(exception);"," "," });"," "," });"," "," $rootScope.$on('facebook:deauthenticated', function () {"," "," delete logins['graph.facebook.com'];"," "," login(logins);"," "," });"," "," $rootScope.$on('google:authenticated', function ($event, authResponse) {"," "," logins['accounts.google.com'] = "," authResponse.id_token;"," "," $log.debug('google:authenticated', logins);"," "," if (authentication) {"," "," authentication.resolve('google');"," "," }"," "," Google.getUser()"," .then(function (result) {"," "," user = {"," email_address: result.getBasicProfile().getEmail(),"," first_name: result.getBasicProfile().getGivenName(),"," full_name: result.getBasicProfile().getName(),"," google: {"," id_token: result.getAuthResponse().id_token,"," granted_scopes: result.getGrantedScopes(),"," hosted_domain: result.getHostedDomain()"," },"," last_name: result.getBasicProfile().getFamilyName(),"," name: result.getBasicProfile().getName(),"," photo_url: result.getBasicProfile().getImageUrl()"," };"," "," if (!authenticateCalled) {"," "," login(logins);"," "," }"," "," })"," .catch(function (exception) {"," "," $log.debug(exception);"," "," });"," "," });"," "," $rootScope.$on('google:deauthenticated', function () {"," "," delete logins['accounts.google.com'];"," "," login(logins);"," "," });"," "," return {"," authenticate: function () {"," "," $log.debug('User.authenticate');"," "," authenticateCalled = true;"," "," // is the user already authenticated"," // then we have credentials"," "," if (identity && expiration.isAfter(moment())) {"," "," $log.debug('identity && expiration', identity, expiration);"," "," return $q.resolve(true);"," "," }"," "," // we don't have credentials"," // ask the providers without displaying dialog"," "," if (!authentication) {"," "," $log.debug('creatting new authentication');"," "," authentication = $q.defer();"," "," }"," "," $log.debug('before race');"," "," return $q.race(["," Facebook.authenticate(),"," Google.authenticate()"," ])"," .catch(function () {"," "," // we could not get credentials from providers"," // display user authentication dialog"," // should return login from provider"," "," return $mdDialog.show({"," clickOutsideToClose: true,"," controller: 'UserAuthenticationController',"," controllerAs: 'crtl',"," escapeToClose: true,"," parent: angular.element(document.body),"," templateUrl: 'user/templates/authentication.html'"," });"," "," })"," .then(function () {"," "," $log.debug('after race');"," "," return authentication.promise;"," "," })"," .then(function () {"," "," // a provider has authed"," // at least one login is available"," // get credentials then resolve promise"," "," $log.debug('after authentication');"," "," return login(logins);"," "," })"," .finally(function () {"," "," authenticateCalled = false;"," "," });"," "," },"," getEnabledProviders: function () {"," "," return {"," email: (enabled.email) ? true : false,"," facebook: (enabled.facebook) ? true : false,"," github: (enabled.github) ? true : false,"," google: (enabled.google) ? true : false,"," linkedin: (enabled.linkedin) ? true : false,"," twitter: (enabled.twitter) ? true : false"," };"," "," },"," logout: function () {"," "," logout();"," "," }"," };"," "," }"," ];"," "," }","])",".provider('UserEmail', ["," function () {"," "," var enabled = false;"," "," this.enable = function (config) {"," "," enabled = true;"," "," };"," "," this.$get = ["," '$q',"," '$rootScope',"," '$window',"," function ($q, $rootScope, $window) {"," "," var authenticated, authentication, ready;"," "," authentication = $q.defer();"," "," ready = $q.defer();"," "," function authed() {"," "," if (authentication.promise.$$state.status !== 0) {"," "," authentication = $q.defer();"," "," }"," "," authenticated = true;"," "," authentication.resolve(true);"," "," $rootScope.$broadcast('facebook:authenticated');"," "," }"," "," function deauthed() {"," "," if (authentication.promise.$$state.status !== 0) {"," "," authentication = $q.defer();"," ","