我正在努力做到这一点,以便当您访问给定路径时,您将被重定向到登录路由。
我遵循了这个 gist中的代码,但它似乎对我的应用程序没有任何影响(一切仍然像以前一样工作,但至少没有任何问题)
我的代码:
App.AuthenticatedRoute = Ember.Route.extend
beforeModel: (transition) ->
if !App.Auth.signedIn
return RSVP.reject();
App.PromptsRoute = App.AuthenticatedRoute
model: -> App.Prompt.find()
error: (reason, transition) ->
loginController = @controllerFor('login')
loginController.set('afterLoginTransition', transition)
@transitionTo(login)
App.LoginController = Ember.Controller.extend
email: null
password: null
remember: true
loginError: null
afterLoginTransition: null
login: () ->
self = @
App.Auth.signIn
data:
email: @get 'email'
password: @get 'password'
remember: @get 'remember'
.done (response) ->
self.clearForm()
self.loginSucceeded()
.fail (response) ->
self.set('loginError', "Your username or password was incorrect. Please try again")
clearForm: ->
self.set('loginError', null)
self.set('email', null)
self.set('password', null)
self.set('recmember', true)
loginSucceeded: ->
transition = @get('afterLoginTransition')
if transition
transition.retry()
else
alert("Boink")