refactor routes/auth interaction so that it always calls afterSignIn()
This commit is contained in:
parent
786d8ebfc6
commit
c4b91108a0
|
@ -30,17 +30,22 @@ Travis.reopen
|
|||
@store = Travis.Store.create()
|
||||
@store.loadMany(Travis.Sponsor, Travis.SPONSORS)
|
||||
|
||||
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
|
||||
# @set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
|
||||
|
||||
@slider = new Travis.Slider()
|
||||
@pusher = new Travis.Pusher(Travis.config.pusher_key)
|
||||
@tailing = new Travis.Tailing()
|
||||
|
||||
initAuth: (router, path) ->
|
||||
auth = Travis.Auth.create(app: this, router: router, endpoint: Travis.config.api_endpoint)
|
||||
@set('auth', auth)
|
||||
auth.loadUser(path)
|
||||
|
||||
signIn: ->
|
||||
@get('auth').signIn()
|
||||
|
||||
autoSignIn: ->
|
||||
@get('auth').autoSignIn()
|
||||
# autoSignIn: ->
|
||||
# @get('auth').autoSignIn()
|
||||
|
||||
signOut: ->
|
||||
@get('auth').signOut()
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
init: ->
|
||||
@iframe.appendTo('body')
|
||||
window.addEventListener('message', (e) => @receiveMessage(e))
|
||||
@loadUser()
|
||||
# @loadUser()
|
||||
|
||||
accessToken: (->
|
||||
sessionStorage.getItem('travis.token')
|
||||
|
@ -15,20 +15,21 @@
|
|||
|
||||
# if the user is in the session storage, we're using it. if we have a flag
|
||||
# for auto signin then we're trying to sign in.
|
||||
loadUser: ->
|
||||
loadUser: (path)->
|
||||
@storeAfterSignInPath(path)
|
||||
if user = sessionStorage.getItem('travis.user')
|
||||
@setData(user: JSON.parse(user))
|
||||
else
|
||||
@autoSignIn()
|
||||
|
||||
# try signing in, but check later in case we have a timeout
|
||||
signIn: ->
|
||||
signIn: (path) ->
|
||||
@set('state', 'signing-in')
|
||||
@trySignIn()
|
||||
Ember.run.later(this, @checkSignIn.bind(this), @timeout)
|
||||
|
||||
autoSignIn: ->
|
||||
@signIn() if localStorage.getItem('travis.auto_signin')
|
||||
autoSignIn: (path) ->
|
||||
@signIn(path) if localStorage.getItem('travis.auto_signin')
|
||||
|
||||
signOut: ->
|
||||
localStorage.removeItem('travis.auto_signin')
|
||||
|
@ -52,7 +53,10 @@
|
|||
user = @storeUser(data.user) if data?.user
|
||||
@set('state', if user then 'signed-in' else 'signed-out')
|
||||
@set('user', if user then user else undefined)
|
||||
router.send('afterSignIn') if router = Travis.app?.get('router')
|
||||
@afterSignIn()
|
||||
|
||||
afterSignIn: ->
|
||||
@get('router').send('afterSignIn', @readAfterSignInPath())
|
||||
|
||||
storeToken: (token) ->
|
||||
sessionStorage.setItem('travis.token', token)
|
||||
|
@ -66,6 +70,14 @@
|
|||
user.get('permissions')
|
||||
user
|
||||
|
||||
storeAfterSignInPath: (path) ->
|
||||
sessionStorage.setItem('travis.after_signin_path', path)
|
||||
|
||||
readAfterSignInPath: ->
|
||||
path = sessionStorage.getItem('travis.after_signin_path')
|
||||
sessionStorage.removeItem('travis.after_signin_path')
|
||||
path
|
||||
|
||||
receiveMessage: (event) ->
|
||||
if event.origin == @expectedOrigin()
|
||||
event.data.user.token = event.data.token if event.data.token
|
||||
|
|
|
@ -151,19 +151,18 @@ Travis.Router = Ember.Router.extend
|
|||
afterSignOut: ->
|
||||
@authorize('/')
|
||||
|
||||
authorize: (path) ->
|
||||
if !@signedIn() && @needsAuth(path)
|
||||
sessionStorage.setItem('travis.after_signin_path', path)
|
||||
@transitionTo('root.auth')
|
||||
Travis.app.autoSignIn()
|
||||
else
|
||||
@transitionTo('root')
|
||||
@route(path)
|
||||
|
||||
loading: Ember.Route.extend
|
||||
routePath: (router, path) ->
|
||||
router.saveLineNumberHash(path)
|
||||
router.authorize(path)
|
||||
router.auth = Travis.app.initAuth(router, path)
|
||||
|
||||
authorize: (path) ->
|
||||
if !@signedIn() && @needsAuth(path)
|
||||
@transitionTo('root.auth')
|
||||
else
|
||||
@transitionTo('root')
|
||||
@route(path)
|
||||
|
||||
root: Ember.Route.extend
|
||||
route: '/'
|
||||
|
@ -178,9 +177,7 @@ Travis.Router = Ember.Router.extend
|
|||
router.get('authLayoutController').connectOutlet('top', 'top')
|
||||
router.get('authLayoutController').connectOutlet('main', 'signin')
|
||||
|
||||
afterSignIn: (router) ->
|
||||
path = sessionStorage.getItem('travis.after_signin_path')
|
||||
sessionStorage.removeItem('travis.after_signin_path')
|
||||
afterSignIn: (router, path) ->
|
||||
router.route(path || '/')
|
||||
|
||||
stats: Ember.Route.extend
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
392e058e
|
||||
0d94ee33
|
Loading…
Reference in New Issue
Block a user