2013-03-15 76 views
2

我使用Ember.js和Rails创建了一个登录系统。所以我试图为未经过身份验证的用户进行重定向。我不知道我必须在哪里做重定向(应用程序控制器或应用程序路线?)。 这里是我的身份验证系统:仅为经过身份验证的用户创建一个限制区域

window.AuthApp = Ember.Object.extend(Ember.Evented).create 
authToken: null 
currentUserId: null 

signIn: (data) -> 
    if data == null 
     data = {} 
    if data['remember'] == true 
     cookie = true 
    $.ajax 'api/login', 
     type: 'POST' 
     dataType: 'JSON', 
     contentType: 'application/json; charset=utf-8' 
     data: JSON.stringify(data) 
     error: -> 
      alert('Error signIn') 
     success: (data) -> 
      console.log(data) 
      AuthApp.set 'authToken', data['auth_token'] 
      if cookie == true 
       $.cookie 'remember_token', data['auth_token'], 
        expires: 7 

AuthApp.Module.RememberMe = Ember.Object.create 
recall: -> 
    if ($.cookie('remember_token')) 
     data = {} 
     data['auth_token'] = $.cookie('remember_token') 
     AuthApp.signIn(data) 
     return true 

正如你所看到的,我只是如果用户连接或不叫AuthApp.Module.Remember.recall()进行检查。 感谢您的帮助

回答

相关问题