add autoSignIn to fix that after signOut it would always re-signin on pages that require auth

This commit is contained in:
Sven Fuchs 2012-10-13 15:52:27 +02:00
parent 44d81af450
commit d84b5dfd0a
6 changed files with 29 additions and 20 deletions

View File

@ -39,6 +39,9 @@ Travis.reopen
signIn: ->
@get('auth').signIn()
autoSignIn: ->
@get('auth').autoSignIn()
signOut: ->
@get('auth').signOut()
@get('router').send('afterSignOut')

View File

@ -18,8 +18,8 @@
loadUser: ->
if user = sessionStorage.getItem('travis.user')
@setData(user: JSON.parse(user))
else if localStorage.getItem('travis.auto_signin')
@trySignIn()
else
@autoSignIn()
# try signing in, but check later in case we have a timeout
signIn: ->
@ -27,6 +27,14 @@
@trySignIn()
Ember.run.later(this, @checkSignIn.bind(this), @timeout)
autoSignIn: ->
@signIn() if localStorage.getItem('travis.auto_signin')
signOut: ->
localStorage.clear()
sessionStorage.clear()
@setData()
trySignIn: ->
@iframe.attr('src', "#{@endpoint}/auth/post_message?origin=#{@receivingEnd}")
@ -37,11 +45,6 @@
localStorage.setItem('travis.auto_signin', 'true')
window.location = "#{@endpoint}/auth/handshake?redirect_uri=#{location}"
signOut: ->
localStorage?.clear()
sessionStorage?.clear()
@setData()
setData: (data) ->
data = JSON.parse(data) if typeof data == 'string'
@storeToken(data.token) if data?.token

View File

@ -148,24 +148,27 @@ Travis.Router = Ember.Router.extend
path.indexOf('/profile') == 0
afterSignIn: ->
after_signin_path = sessionStorage.getItem('travis.after_signin_path')
path = sessionStorage.getItem('travis.after_signin_path')
sessionStorage.removeItem('travis.after_signin_path')
@transitionTo('root')
@route(after_signin_path || '/')
@route(path || '/')
afterSignOut: ->
@transitionTo('loading')
@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)
if !router.signedIn() && router.needsAuth(path)
sessionStorage.setItem('travis.after_signin_path', path)
router.transitionTo('root.auth')
Travis.app.signIn()
else
router.transitionTo('root')
router.route(path)
router.authorize(path)
root: Ember.Route.extend
route: '/'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
b35f89d1
5fb464fb