Created
October 15, 2014 07:01
-
-
Save cades/3cdce5fb555465ad8484 to your computer and use it in GitHub Desktop.
登入 Google 帳號的 AngularJS directive。 HackNTU 的產出之一,未完成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('calenshareApp') | |
.factory('GoogleAuth', function () { | |
(function() { | |
var po = document.createElement('script'); | |
po.type = 'text/javascript'; po.async = true; | |
po.src = 'https://apis.google.com/js/client:plusone.js?onload=render'; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(po, s); | |
})(); | |
/* Executed when the APIs finish loading */ | |
function render() { | |
// Additional params including the callback, the rest of the params will | |
// come from the page-level configuration. | |
var additionalParams = { | |
'callback': function (authResult){ | |
if (authResult['status']['signed_in']) { | |
// Update the app to reflect a signed in user | |
// Hide the sign-in button now that the user is authorized, for example: | |
document.getElementById('signinButton').setAttribute('style', 'display: none'); | |
} else { | |
// Update the app to reflect a signed out user | |
// Possible error values: | |
// "user_signed_out" - User is signed-out | |
// "access_denied" - User denied access to your app | |
// "immediate_failed" - Could not automatically log in the user | |
console.log('Sign-in state: ' + authResult['error']); | |
} | |
} | |
}; | |
// Attach a click listener to a button to trigger the flow. | |
var signinButton = document.getElementById('signinButton'); | |
signinButton.addEventListener('click', function() { | |
gapi.auth.signIn(additionalParams); // Will use page level configuration | |
}); | |
} | |
return { | |
signIn: function(){ | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment