This commit is contained in:
Scott Erickson 2015-02-13 11:18:00 -08:00
parent 574f0b1442
commit 9b86e5872f
4 changed files with 11 additions and 30 deletions

View file

@ -172,7 +172,7 @@ module.exports = class CocoRouter extends Backbone.Router
callback: 'signinCallback',
clientid: gplusClientID,
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',
}
if gapi.signin?.render

View file

@ -9,7 +9,7 @@ module.exports = initializeGoogle = ->
po = document.createElement('script')
po.type = 'text/javascript'
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.parentNode.insertBefore po, s
return

View file

@ -61,39 +61,25 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass
loginCodeCombat: ->
# email and profile data loaded separately
gapi.client.request(path: plusURL, callback: @onPersonEntityReceived)
gapi.client.load('oauth2', 'v2', =>
gapi.client.oauth2.userinfo.get().execute(@onEmailReceived))
gapi.client.load('plus', 'v1', =>
gapi.client.plus.people.get({userId: 'me'}).execute(@onPersonReceived))
shouldSave: false
onPersonEntityReceived: (r) =>
onPersonReceived: (r) =>
for gpProp, userProp of userPropsToSave
keys = gpProp.split('.')
value = r
for key in keys
value = value[key]
if value and not me.get(userProp)
@shouldSave = true
me.set(userProp, value)
@responsesComplete += 1
@personLoaded = true
@trigger 'person-loaded'
@saveIfAllDone()
onEmailReceived: (r) =>
newEmail = r.email and r.email isnt me.get('email')
newEmail = r.emails?.length and r.emails[0] isnt me.get('email')
return unless newEmail or me.get('anonymous', true)
me.set('email', r.email)
@shouldSave = true
@emailLoaded = true
@trigger 'email-loaded'
@saveIfAllDone()
me.set('email', r.emails[0].value)
@trigger 'person-loaded'
@save()
saveIfAllDone: =>
console.debug 'Save if all done. Person loaded:', @personLoaded, 'and email loaded:', @emailLoaded
return unless @personLoaded and @emailLoaded
save: =>
console.debug 'Email, gplusID:', me.get('email'), 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: [
{ i18n: 'login.authenticate_gplus', done: false }
{ i18n: 'login.load_profile', done: false }
{ i18n: 'login.load_email', done: false }
{ i18n: 'login.finishing', done: false }
]
@ -136,12 +135,8 @@ module.exports = class AuthModal extends ModalView
@gplusAuthSteps[1].done = true
@renderGPlusAuthChecklist()
@listenToOnce handler, 'email-loaded', ->
@gplusAuthSteps[2].done = true
@renderGPlusAuthChecklist()
@listenToOnce handler, 'logging-into-codecombat', ->
@gplusAuthSteps[3].done = true
@gplusAuthSteps[2].done = true
@renderGPlusAuthChecklist()
renderGPlusAuthChecklist: ->