mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
248d6dd1ef
4 changed files with 12 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@ fieldsToFetch = 'displayName,gender,image,name(familyName,givenName),id'
|
|||
plusURL = '/plus/v1/people/me?fields='+fieldsToFetch
|
||||
revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token='
|
||||
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
|
||||
constructor: ->
|
||||
|
@ -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')
|
||||
|
||||
|
|
|
@ -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: ->
|
||||
|
|
Loading…
Reference in a new issue