Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Barney 2015-02-14 03:53:47 +08:00
commit 248d6dd1ef
4 changed files with 12 additions and 31 deletions

View file

@ -172,7 +172,7 @@ module.exports = class CocoRouter extends Backbone.Router
callback: 'signinCallback', callback: 'signinCallback',
clientid: gplusClientID, clientid: gplusClientID,
cookiepolicy: 'single_host_origin', cookiepolicy: 'single_host_origin',
scope: 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email', scope: 'https://www.googleapis.com/auth/plus.login email',
height: 'short', height: 'short',
} }
if gapi.signin?.render if gapi.signin?.render

View file

@ -9,7 +9,7 @@ module.exports = initializeGoogle = ->
po = document.createElement('script') po = document.createElement('script')
po.type = 'text/javascript' po.type = 'text/javascript'
po.async = true po.async = true
po.src = 'https://apis.google.com/js/client:plusone.js?onload=onGPlusLoaded' po.src = 'https://apis.google.com/js/client:platform.js?onload=onGPlusLoaded'
s = document.getElementsByTagName('script')[0] s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore po, s s.parentNode.insertBefore po, s
return return

View file

@ -15,7 +15,7 @@ fieldsToFetch = 'displayName,gender,image,name(familyName,givenName),id'
plusURL = '/plus/v1/people/me?fields='+fieldsToFetch plusURL = '/plus/v1/people/me?fields='+fieldsToFetch
revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token='
clientID = '800329290710-j9sivplv2gpcdgkrsis9rff3o417mlfa.apps.googleusercontent.com' clientID = '800329290710-j9sivplv2gpcdgkrsis9rff3o417mlfa.apps.googleusercontent.com'
scope = 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email' scope = 'https://www.googleapis.com/auth/plus.login email'
module.exports = GPlusHandler = class GPlusHandler extends CocoClass module.exports = GPlusHandler = class GPlusHandler extends CocoClass
constructor: -> constructor: ->
@ -61,39 +61,25 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass
loginCodeCombat: -> loginCodeCombat: ->
# email and profile data loaded separately # email and profile data loaded separately
gapi.client.request(path: plusURL, callback: @onPersonEntityReceived) gapi.client.load('plus', 'v1', =>
gapi.client.load('oauth2', 'v2', => gapi.client.plus.people.get({userId: 'me'}).execute(@onPersonReceived))
gapi.client.oauth2.userinfo.get().execute(@onEmailReceived))
shouldSave: false onPersonReceived: (r) =>
onPersonEntityReceived: (r) =>
for gpProp, userProp of userPropsToSave for gpProp, userProp of userPropsToSave
keys = gpProp.split('.') keys = gpProp.split('.')
value = r value = r
for key in keys for key in keys
value = value[key] value = value[key]
if value and not me.get(userProp) if value and not me.get(userProp)
@shouldSave = true
me.set(userProp, value) me.set(userProp, value)
@responsesComplete += 1 newEmail = r.emails?.length and r.emails[0] isnt me.get('email')
@personLoaded = true
@trigger 'person-loaded'
@saveIfAllDone()
onEmailReceived: (r) =>
newEmail = r.email and r.email isnt me.get('email')
return unless newEmail or me.get('anonymous', true) return unless newEmail or me.get('anonymous', true)
me.set('email', r.email) me.set('email', r.emails[0].value)
@shouldSave = true @trigger 'person-loaded'
@emailLoaded = true @save()
@trigger 'email-loaded'
@saveIfAllDone()
saveIfAllDone: => save: =>
console.debug 'Save if all done. Person loaded:', @personLoaded, 'and email loaded:', @emailLoaded
return unless @personLoaded and @emailLoaded
console.debug 'Email, gplusID:', me.get('email'), me.get('gplusID') console.debug 'Email, gplusID:', me.get('email'), me.get('gplusID')
return unless me.get('email') and me.get('gplusID') return unless me.get('email') and me.get('gplusID')

View file

@ -119,7 +119,6 @@ module.exports = class AuthModal extends ModalView
gplusAuthSteps: [ gplusAuthSteps: [
{ i18n: 'login.authenticate_gplus', done: false } { i18n: 'login.authenticate_gplus', done: false }
{ i18n: 'login.load_profile', done: false } { i18n: 'login.load_profile', done: false }
{ i18n: 'login.load_email', done: false }
{ i18n: 'login.finishing', done: false } { i18n: 'login.finishing', done: false }
] ]
@ -136,12 +135,8 @@ module.exports = class AuthModal extends ModalView
@gplusAuthSteps[1].done = true @gplusAuthSteps[1].done = true
@renderGPlusAuthChecklist() @renderGPlusAuthChecklist()
@listenToOnce handler, 'email-loaded', ->
@gplusAuthSteps[2].done = true
@renderGPlusAuthChecklist()
@listenToOnce handler, 'logging-into-codecombat', -> @listenToOnce handler, 'logging-into-codecombat', ->
@gplusAuthSteps[3].done = true @gplusAuthSteps[2].done = true
@renderGPlusAuthChecklist() @renderGPlusAuthChecklist()
renderGPlusAuthChecklist: -> renderGPlusAuthChecklist: ->