Improve auth code in router by using new async stuff (❤️ @machty)
This commit is contained in:
parent
d9d833d1b4
commit
9170795639
|
@ -70,10 +70,9 @@
|
|||
Travis.setLocale(data.user.locale || Travis.default_locale)
|
||||
Travis.trigger('user:signed_in', data.user)
|
||||
if router = Travis.__container__.lookup('router:main')
|
||||
path = @readAfterSignInPath()
|
||||
Ember.run.next =>
|
||||
try
|
||||
router.send('afterSignIn', path)
|
||||
router.send('afterSignIn')
|
||||
catch e
|
||||
throw e unless e =~ /There are no active handlers/
|
||||
@refreshUserData(data.user)
|
||||
|
@ -100,14 +99,6 @@
|
|||
user.get('permissions')
|
||||
user
|
||||
|
||||
storeAfterSignInPath: (path) ->
|
||||
Travis.sessionStorage.setItem('travis.after_signin_path', path)
|
||||
|
||||
readAfterSignInPath: ->
|
||||
path = Travis.sessionStorage.getItem('travis.after_signin_path')
|
||||
Travis.sessionStorage.removeItem('travis.after_signin_path')
|
||||
path
|
||||
|
||||
receiveMessage: (event) ->
|
||||
if event.origin == @expectedOrigin()
|
||||
if event.data == 'redirect'
|
||||
|
|
|
@ -5,8 +5,6 @@ Ember.Router.reopen
|
|||
location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create())
|
||||
|
||||
handleURL: (url) ->
|
||||
Travis.autoSignIn() unless Travis.__container__.lookup('controller:currentUser').get('content')
|
||||
|
||||
url = url.replace(/#.*?$/, '')
|
||||
try
|
||||
@_super(url)
|
||||
|
@ -26,22 +24,35 @@ Ember.Route.reopen
|
|||
renderNoOwnedRepos: ->
|
||||
@render('no_owned_repos', outlet: 'main')
|
||||
|
||||
error: (error) ->
|
||||
if error == 'needs-auth'
|
||||
@transitionTo('auth')
|
||||
else
|
||||
throw(error)
|
||||
|
||||
afterSignIn: (path) ->
|
||||
@afterSignIn(path)
|
||||
|
||||
afterSignOut: ->
|
||||
@afterSignOut()
|
||||
|
||||
afterSignIn: (path) ->
|
||||
@routeToPath(path)
|
||||
afterSignIn: ->
|
||||
if transition = Travis.auth.get('afterSignInTransition')
|
||||
Travis.auth.set('afterSignInTransition', null)
|
||||
transition.retry()
|
||||
|
||||
afterSignOut: ->
|
||||
@routeToPath('/')
|
||||
@transitionTo('index.current')
|
||||
|
||||
routeToPath: (path) ->
|
||||
return unless path
|
||||
@router.handleURL(path)
|
||||
@router.location.setURL(path)
|
||||
beforeModel: (transition) ->
|
||||
Travis.autoSignIn() unless @signedIn()
|
||||
|
||||
if !@signedIn() && @get('needsAuth')
|
||||
Travis.auth.set('afterSignInTransition', transition)
|
||||
transition.abort()
|
||||
Ember.RSVP.reject("needs-auth")
|
||||
else
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
signedIn: ->
|
||||
@controllerFor('currentUser').get('content')
|
||||
|
@ -65,7 +76,6 @@ Travis.Router.reopen
|
|||
|
||||
@_super.apply this, arguments
|
||||
|
||||
|
||||
Travis.Router.map ->
|
||||
@resource 'index', path: '/', ->
|
||||
@route 'current', path: '/'
|
||||
|
@ -346,7 +356,7 @@ Travis.AccountRoute = Ember.Route.extend
|
|||
proxy
|
||||
|
||||
serialize: (account) ->
|
||||
if account
|
||||
if account && account.get
|
||||
{ login: account.get('login') }
|
||||
else
|
||||
{}
|
||||
|
|
Loading…
Reference in New Issue
Block a user