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