仅为经过身份验证的用户创建受限区域

时间:2013-03-15 13:54:28

标签: ember.js

我已经使用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()来检查用户是否已连接。 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

你应该看一下router-facelift。其中一个设计目标是使基于身份验证的应用程序更难实现。

https://gist.github.com/machty/5723945