mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
467955dc2c
commit 64938016f6ffbf366a220e7abd9af6f7a4cb478b Author: Ben Gotow <bengotow@gmail.com> Date: Sun Oct 4 16:42:38 2015 -0700 Don't allow people to double click the token check button, make requests take at least 400msec commit e548f3ee449c676a813c5630f1624963872ed6e6 Merge: 3350b91 e4b4933 Author: Ben Gotow <bengotow@gmail.com> Date: Sun Oct 4 16:39:56 2015 -0700 Merge branch 'token-auth' of github.com:nylas/N1 into token-auth # Conflicts: # internal_packages/onboarding/lib/token-auth-page.cjsx commit 3350b917449c29299fa078d59a4a5a9339fdf29b Author: Ben Gotow <bengotow@gmail.com> Date: Sun Oct 4 16:38:52 2015 -0700 Improve a few error states, adding "checking" state when checking token commit e4b49334cbf59145d9bdd955d35636f16a7c4924 Author: EthanBlackburn <ethan@nylas.com> Date: Sun Oct 4 16:21:39 2015 -0700 Correct retry behavior commit 11cd9a75b2a1ca0f4347160df93815743909ccea Author: EthanBlackburn <ethan@nylas.com> Date: Sat Oct 3 18:06:55 2015 -0700 Removed old auth token variable commit afe451cd70de528def3443d8b373fd24f4aa5cde Author: EthanBlackburn <ethan@nylas.com> Date: Sat Oct 3 16:08:12 2015 -0700 Added token auth page
88 lines
2.4 KiB
CoffeeScript
88 lines
2.4 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
OnboardingActions = require './onboarding-actions'
|
|
TokenAuthAPI = require './token-auth-api'
|
|
{AccountStore} = require 'nylas-exports'
|
|
NylasStore = require 'nylas-store'
|
|
ipc = require 'ipc'
|
|
url = require 'url'
|
|
|
|
return unless atom.getWindowType() is "onboarding"
|
|
|
|
class PageRouterStore extends NylasStore
|
|
constructor: ->
|
|
atom.onWindowPropsReceived @_onWindowPropsChanged
|
|
|
|
@_page = atom.getWindowProps().page ? ''
|
|
@_pageData = atom.getWindowProps().pageData ? {}
|
|
@_pageStack = [{page: @_page, pageData: @_pageData}]
|
|
|
|
@_checkTokenAuthStatus()
|
|
|
|
@listenTo OnboardingActions.moveToPreviousPage, @_onMoveToPreviousPage
|
|
@listenTo OnboardingActions.moveToPage, @_onMoveToPage
|
|
@listenTo OnboardingActions.closeWindow, @_onCloseWindow
|
|
@listenTo OnboardingActions.accountJSONReceived, @_onAccountJSONReceived
|
|
@listenTo OnboardingActions.retryCheckTokenAuthStatus, @_checkTokenAuthStatus
|
|
|
|
_onAccountJSONReceived: (json) =>
|
|
isFirstAccount = AccountStore.items().length is 0
|
|
AccountStore.addAccountFromJSON(json)
|
|
ipc.send('new-account-added')
|
|
atom.displayWindow()
|
|
if isFirstAccount
|
|
@_onMoveToPage('initial-preferences', {account: json})
|
|
else
|
|
ipc.send('account-setup-successful')
|
|
|
|
_onWindowPropsChanged: ({page, pageData}={}) =>
|
|
@_onMoveToPage(page, pageData)
|
|
|
|
page: -> @_page
|
|
|
|
pageData: -> @_pageData
|
|
|
|
tokenAuthEnabled: -> @_tokenAuthEnabled
|
|
|
|
tokenAuthEnabledError: -> @_tokenAuthEnabledError
|
|
|
|
connectType: ->
|
|
@_connectType
|
|
|
|
_onMoveToPreviousPage: ->
|
|
current = @_pageStack.pop()
|
|
prev = @_pageStack.pop()
|
|
@_onMoveToPage(prev.page, prev.pageData)
|
|
|
|
_onMoveToPage: (page, pageData={}) ->
|
|
@_pageStack.push({page, pageData})
|
|
@_page = page
|
|
@_pageData = pageData
|
|
@trigger()
|
|
|
|
_onCloseWindow: ->
|
|
isFirstAccount = AccountStore.items().length is 0
|
|
if isFirstAccount
|
|
atom.quit()
|
|
else
|
|
atom.close()
|
|
|
|
_checkTokenAuthStatus: ->
|
|
@_tokenAuthEnabled = "unknown"
|
|
@_tokenAuthEnabledError = null
|
|
@trigger()
|
|
|
|
TokenAuthAPI.request
|
|
path: "/status"
|
|
returnsModel: false
|
|
timeout: 10000
|
|
success: (json) =>
|
|
if json.restricted
|
|
@_tokenAuthEnabled = "yes"
|
|
else
|
|
@_tokenAuthEnabled = "no"
|
|
@trigger()
|
|
error: (err) =>
|
|
@_tokenAuthEnabledError = err.message
|
|
@trigger()
|
|
|
|
module.exports = new PageRouterStore()
|