Skip to content

Instantly share code, notes, and snippets.

@joncodo
Created August 5, 2014 18:20
Show Gist options
  • Select an option

  • Save joncodo/559f7903d8a94f234c02 to your computer and use it in GitHub Desktop.

Select an option

Save joncodo/559f7903d8a94f234c02 to your computer and use it in GitHub Desktop.
app.service("googlePlusService", function($http, $rootScope) {
return {
start: function() {
console.log('start');
this.renderGooglePlusButton();
},
renderGooglePlusButton: function() {
console.log('render sign in button');
gapi.signin.render('signInButton',
{
'scope': "email",
'clientid': "397019550339-16ihtl6aj49rglqv9adh1knqrn4hrn1p.apps.googleusercontent.com",
'callback': "processGooglePlusAuth",
'theme': "dark",
'cookiepolicy': "single_host_origin"
}
);
},
processGooglePlusAuth: function(authResult) {
console.log('process auth');
console.log('isUserSignedIn: ' + authResult['status']['signed_in']);
if (authResult['status']['signed_in']) {
//sign the user into the dashboard
gapi.client.load('plus', 'v1', function () {
console.log('in the plus email call');
var request = gapi.client.plus.people.get({
'userId': 'me'
});
var response;
request.execute(function (resp) {
response = resp;
var primaryEmail;
if(resp.emails != undefined){
resp.emails.forEach(function(email){
if(email.type == 'account'){
primaryEmail = email.value;
}
});
}
console.log('google plus email:' + primaryEmail);
console.log('Retrieved profile for:' + resp.displayName);
console.log('image at:' + resp.image.url);
console.log('google plus id:' + resp.id);
});
this.foo();
});
//create the user in our db
//redirect them to the dashboard every time they are on the login page
}
else{
//Redirect the user back to the login url with a message of ?
}
},
foo: function(){
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment