1"use strict"; 2 3var socialLogin = angular.module('socialLogin', []); 4 5socialLogin.provider("social", function(){ 6 var fbKey, fbApiV, googleKey, linkedInKey; 7 return { 8 setFbKey: function(obj){ 9 fbKey = obj.appId; 10 fbApiV = obj.apiVersion; 11 var d = document, fbJs, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 12 fbJs = d.createElement('script'); 13 fbJs.id = id; 14 fbJs.async = true; 15 fbJs.src = "//connect.facebook.net/en_US/sdk.js"; 16 17 fbJs.onload = function() { 18 FB.init({ 19 appId: fbKey, 20 status: true, 21 cookie: true, 22 xfbml: true, 23 version: fbApiV 24 }); 25 }; 26 27 ref.parentNode.insertBefore(fbJs, ref); 28 }, 29 setGoogleKey: function(value){ 30 googleKey = value; 31 var d = document, gJs, ref = d.getElementsByTagName('script')[0]; 32 gJs = d.createElement('script'); 33 gJs.async = true; 34 gJs.src = "https://apis.google.com/js/client:plusone.js" 35 36 gJs.onload = function() { 37 var params ={ 38 client_id: value, 39 scope: 'email' 40 } 41 gapi.load('auth2', function() { 42 gapi.auth2.init(params); 43 }); 44 }; 45 46 ref.parentNode.insertBefore(gJs, ref); 47 }, 48 setLinkedInKey: function(value){ 49 linkedInKey = value; 50 var lIN, d = document, ref = d.getElementsByTagName('script')[0]; 51 lIN = d.createElement('script'); 52 lIN.async = false; 53 lIN.src = "//platform.linkedin.com/in.js?async=false"; 54 lIN.text = ("api_key: " + linkedInKey).replace("\"", ""); 55 ref.parentNode.insertBefore(lIN, ref); 56 }, 57 $get: function(){ 58 return{ 59 fbKey: fbKey, 60 googleKey: googleKey, 61 linkedInKey: linkedInKey, 62 fbApiV: fbApiV 63 } 64 } 65 } 66}); 67 68socialLogin.factory("socialLoginService", function($window, $rootScope){ 69 return { 70 logout: function(){ 71 var provider = $window.localStorage.getItem('_login_provider'); 72 switch(provider) { 73 case "google": 74 //its a hack need to find better solution. 75 var gElement = document.getElementById("gSignout"); 76 if (typeof(gElement) != 'undefined' && gElement != null) 77 { 78 gElement.remove(); 79 } 80 var d = document, gSignout, ref = d.getElementsByTagName('script')[0]; 81 gSignout = d.createElement('script'); 82 gSignout.src = "https://accounts.google.com/Logout"; 83 gSignout.type = "text/javascript"; 84 gSignout.id = "gSignout"; 85 $window.localStorage.removeItem('_login_provider'); 86 $rootScope.$broadcast('event:social-sign-out-success', "success"); 87 ref.parentNode.insertBefore(gSignout, ref); 88 break; 89 case "linkedIn": 90 IN.User.logout(function(){ 91 $window.localStorage.removeItem('_login_provider'); 92 $rootScope.$broadcast('event:social-sign-out-success', "success"); 93 }, {}); 94 break; 95 case "facebook": 96 FB.logout(function(res){ 97 $window.localStorage.removeItem('_login_provider'); 98 $rootScope.$broadcast('event:social-sign-out-success', "success"); 99 }); 100 break; 101 } 102 }, 103 setProvider: function(provider){ 104 $window.localStorage.setItem('_login_provider', provider); 105 } 106 } 107}); 108 109socialLogin.factory("fbService", function($q){ 110 return { 111 login: function(){ 112 var deferred = $q.defer(); 113 FB.login(function(res){ 114 deferred.resolve(res); 115 }, {scope: 'email', auth_type: 'rerequest'}); 116 return deferred.promise; 117 }, 118 getUserDetails: function(){ 119 var deferred = $q.defer(); 120 FB.api('/me?fields=first_name,last_name,email,picture.width(800).height(800)', function(res){ 121 if(!res || res.error){ 122 deferred.reject('Error occured while fetching user details.'); 123 }else{ 124 deferred.resolve(res); 125 } 126 }); 127 return deferred.promise; 128 } 129 } 130}); 131 132socialLogin.directive("linkedIn", function($rootScope, social, socialLoginService, $window){ 133 return { 134 restrict: 'EA', 135 scope: {}, 136 link: function(scope, ele, attr){ 137 ele.on("click", function(){ 138 IN.User.authorize(function(){ 139 IN.API.Raw("/people/~:(id,first-name,last-name,email-address,picture-url)").result(function(res){ 140 socialLoginService.setProvider("linkedIn"); 141 var userDetails = {first_name: res.firstName, last_name: res.lastName, email: res.emailAddress, uid: res.id, provider: "linkedIN", imageUrl: res.pictureUrl}; 142 $rootScope.$broadcast('event:social-sign-in-success', userDetails); 143 }); 144 }); 145 }) 146 } 147 } 148}) 149 150socialLogin.directive("gLogin", function($rootScope, social, socialLoginService){ 151 return { 152 restrict: 'EA', 153 scope: {}, 154 replace: true, 155 link: function(scope, ele, attr){ 156 ele.on('click', function(){ 157 if(typeof(scope.gauth) == "undefined") 158 scope.gauth = gapi.auth2.getAuthInstance(); 159 scope.gauth.signIn().then(function(googleUser){ 160 var profile = googleUser.getBasicProfile(); 161 var idToken = googleUser.getAuthResponse().id_token 162 socialLoginService.setProvider("google"); 163 $rootScope.$broadcast('event:social-sign-in-success', {token: idToken, name: profile.getName(), email: profile.getEmail(), uid: profile.getId(), provider: "google", lastName: profile.getFamilyName(), firstName: profile.getGivenName(), imageUrl: profile.getImageUrl()}); 164 }, function(err){ 165 console.log(err); 166 }) 167 }); 168 } 169 } 170}); 171 172socialLogin.directive("fbLogin", function($rootScope, fbService, social, socialLoginService){ 173 return { 174 restrict: 'A', 175 scope: {}, 176 replace: true, 177 link: function(scope, ele, attr){ 178 ele.on('click', function(){ 179 fbService.login().then(function(res){ 180 if(res.status == "connected"){ 181 fbService.getUserDetails().then(function(user){ 182 socialLoginService.setProvider("facebook"); 183 var userDetails = {first_name: user.first_name, last_name : user.last_name, email: user.email, uid: user.id, provider: "facebook", imageUrl: user.picture.data.url} 184 $rootScope.$broadcast('event:social-sign-in-success', userDetails); 185 }, function(err){ 186 console.log(err); 187 }) 188 } 189 }, function(err){ 190 console.log(err); 191 }); 192 }); 193 } 194 } 195})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.