diff --git a/app/core/Router.coffee b/app/core/Router.coffee index ddfd47788..8d27d9b14 100644 --- a/app/core/Router.coffee +++ b/app/core/Router.coffee @@ -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 diff --git a/app/core/services/google.coffee b/app/core/services/google.coffee index bda5d1d24..2b51765ee 100644 --- a/app/core/services/google.coffee +++ b/app/core/services/google.coffee @@ -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 diff --git a/app/core/social-handlers/GPlusHandler.coffee b/app/core/social-handlers/GPlusHandler.coffee index d6f8eb813..e1280d5e5 100644 --- a/app/core/social-handlers/GPlusHandler.coffee +++ b/app/core/social-handlers/GPlusHandler.coffee @@ -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') diff --git a/app/views/core/AuthModal.coffee b/app/views/core/AuthModal.coffee index 9b52bd013..8e4a2368d 100644 --- a/app/views/core/AuthModal.coffee +++ b/app/views/core/AuthModal.coffee @@ -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: ->