灰烬认证范式 [英] Ember Authentication paradigm

查看:92
本文介绍了灰烬认证范式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们考虑一个简单的用例:用户编辑其个人资料+我们有一个RESTful服务器。这意味着我们必须
向服务器发送令牌,并同时发送有关编辑的新信息。首先,服务器必须解码令牌,然后再对数据库进行CRUD。我们还希望将有关新用户配置文件的新json模型发送回客户端。

Let's consider a trivial use case: User edits his profile + we have a RESTful server. This means we have to send a token to the server and at the same time the new information about the editing. First, the server has to decode the token, and later to CRUD the DB. We want also to send back to the client a new json model about the new user profile.

但是令牌确实是一个巨大的令牌,因此我们必须使用一个POST请求。我们可以在同一HTTP Post上将其他信息作为查询字符串发送。 Ember Data无法让我们决定是否发送POST请求。因此,我们必须编写手册Em​​ber。$。ajax。但是,我们如何将新的用户模型检索到Ember?我们想利用Ember Data ORM的关系,而不是重新发明轮子。

BUT the token is really a huge one, so we must send it with a POST request. We can send the additional information as a query string at the same HTTP Post. Ember Data doesn't give us the ability to decide on sending a POST request. So we have to write a manual Ember.$.ajax. But how would we retrieve the new user model to Ember? We want to take advantage of Ember Data ORM's relationships and not reinventing the wheel.

仅作记录,在EditController上的手动有效发布请求是(在启用CORS后服务器)+(在我的情况下为fBSignedRequest =>令牌):

Just for the record, the manual valid post request on the EditController is (after enabling CORS on the server)+(fBSignedRequest=> the token in my case):

Ember.$.ajax('http://myapi.com/api/usrEdit?Name='+myNewName, {  
             type: 'POST',
             dataType: "json",
             data: {fBSignedRequest: this.get("FBSignedRequest")},
             success: function(data, response) {
                 console.log(data, response);
                 App.newUserProfile = data; //want it to become a part of the ED ORM
             },
             error: function (xhr) {
                 console.log('error')
             }
});

这确实是一个微不足道的任务。为什么我一个月都找不到答案?

This is really a trivial task to ask. Why couldn't I found any answer for over a month for this? How would you do the combination of a manual ajax and a build in Ember Data ORM?

如果您对整个身份验证有其他想法,我将很高兴听到。

If you have another idea about this whole authentication, I will be glad to hear.

非常感谢!

推荐答案

您可以简单地 push 您通过请求检索到商店的模型。参见 http://emberjs.com/guides/models/pushing-records -进入商店/

You could simply push the model you retrieve via your request into the store. See http://emberjs.com/guides/models/pushing-records-into-the-store/

这篇关于灰烬认证范式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆