diff --git a/app/lib/GPlusHandler.coffee b/app/lib/GPlusHandler.coffee index bb1f8b662..e69c7db79 100644 --- a/app/lib/GPlusHandler.coffee +++ b/app/lib/GPlusHandler.coffee @@ -28,7 +28,7 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass onGPlusLoaded: -> session_state = null - if @accessToken + if @accessToken and me.get('gplusID') # We need to check the current state, given our access token gapi.auth.setToken 'token', @accessToken session_state = @accessToken.session_state @@ -50,19 +50,22 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass onGPlusLogin: (e) => @loggedIn = true - storage.save(GPLUS_TOKEN_KEY, e) + try + # Without removing this, we sometimes get a cross-domain error + d = JSON.stringify(_.omit(e, 'g-oauth-window')) + storage.save(GPLUS_TOKEN_KEY, d) + catch e + console.error 'Unable to save G+ token key', e @accessToken = e @trigger 'logged-in' - return if (not me) or me.get 'gplusID' # so only get more data - + + loginCodeCombat: -> # email and profile data loaded separately - @responsesComplete = 0 gapi.client.request(path: plusURL, callback: @onPersonEntityReceived) gapi.client.load('oauth2', 'v2', => gapi.client.oauth2.userinfo.get().execute(@onEmailReceived)) shouldSave: false - responsesComplete: 0 onPersonEntityReceived: (r) => for gpProp, userProp of userPropsToSave @@ -74,18 +77,21 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass me.set(userProp, value) @responsesComplete += 1 + @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') + return unless newEmail or me.get('anonymous', true) me.set('email', r.email) @shouldSave = true - @responsesComplete += 1 + @emailLoaded = true + @trigger 'email-loaded' @saveIfAllDone() saveIfAllDone: => - return unless @responsesComplete is 2 + return unless @personLoaded and @emailLoaded return unless me.get('email') and me.get('gplusID') Backbone.Mediator.publish 'auth:logging-in-with-gplus', {} @@ -97,6 +103,7 @@ module.exports = GPlusHandler = class GPlusHandler extends CocoClass patch._id = me.id patch.email = me.get('email') wasAnonymous = me.get('anonymous') + @trigger 'logging-into-codecombat' me.save(patch, { patch: true type: 'PUT' diff --git a/app/locale/en.coffee b/app/locale/en.coffee index 8e7f2115b..3582654a7 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -95,6 +95,10 @@ logging_in: "Logging In" log_out: "Log Out" recover: "recover account" + authenticate_gplus: 'Authenticate G+' + load_profile: 'Load G+ Profile' + load_email: 'Load G+ Email' + finishing: 'Finishing' signup: create_account_title: "Create Account to Save Progress" diff --git a/app/templates/modal/auth-modal-gplus-checklist.jade b/app/templates/modal/auth-modal-gplus-checklist.jade new file mode 100644 index 000000000..8cf76a85f --- /dev/null +++ b/app/templates/modal/auth-modal-gplus-checklist.jade @@ -0,0 +1,7 @@ +ul.list-group + for step in steps + li.list-group-item(class=step.done ? 'list-group-item-success' : 'list-group-item-warning') + span(data-i18n=step.i18n) + if step.done + span.glyphicon.glyphicon-ok.pull-right + \ No newline at end of file diff --git a/app/views/modal/AuthModal.coffee b/app/views/modal/AuthModal.coffee index c0f096aa0..5ae45badc 100644 --- a/app/views/modal/AuthModal.coffee +++ b/app/views/modal/AuthModal.coffee @@ -18,6 +18,7 @@ module.exports = class AuthModal extends ModalView 'click #github-login-button': 'onGitHubLoginClicked' 'submit': 'onSubmitForm' # handles both submit buttons 'keyup #name': 'onNameChange' + 'click #gplus-login-button': 'onClickGPlusLogin' subscriptions: 'errors:server-error': 'onServerError' @@ -113,3 +114,39 @@ module.exports = class AuthModal extends ModalView onGitHubLoginClicked: -> Backbone.Mediator.publish 'auth:log-in-with-github', {} + + gplusAuthSteps: [ + { i18n: 'login.authenticate_gplus', done: false } + { i18n: 'login.load_profile', done: false } + { i18n: 'login.load_email', done: false } + { i18n: 'login.finishing', done: false } + ] + + onClickGPlusLogin: -> + step.done = false for step in @gplusAuthSteps + handler = application.gplusHandler + + @renderGPlusAuthChecklist() + + @listenToOnce handler, 'logged-in', -> + @gplusAuthSteps[0].done = true + @renderGPlusAuthChecklist() + handler.loginCodeCombat() + @listenToOnce handler, 'person-loaded', -> + @gplusAuthSteps[1].done = true + @renderGPlusAuthChecklist() + + @listenToOnce handler, 'email-loaded', -> + @gplusAuthSteps[2].done = true + @renderGPlusAuthChecklist() + + @listenToOnce handler, 'logging-into-codecombat', -> + @gplusAuthSteps[3].done = true + @renderGPlusAuthChecklist() + + renderGPlusAuthChecklist: -> + template = require 'templates/modal/auth-modal-gplus-checklist' + el = $(template({steps: @gplusAuthSteps})) + el.i18n() + @$el.find('.modal-body:visible').empty().append(el) + @$el.find('.modal-footer').remove()