我认为标题几乎都说明了......对于Deployd来说是全新的,所以任何关于如何最好地解决这个问题的指针都会受到赞赏.
小智 5
要获取用户创建的集合中的对象(我假设您使用的是javascript库dpd.js):
// Get the current user:
var currentUser;
dpd.users.me(function(result, error) {
currentUser = result;
});
// query your collection with your currentUser id as parameter
dpd.yourcollection.get({creator:currentUser.id}, function(result) {
// Do something with the result
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
您的集合应该具有属性"创建者",其中包含创建对象(*)的用户的ID.然后,为了保护您的后端,请转到集合的ON_GET选项卡中的仪表板,并使用以下代码保护它:
cancelUnless(isMe(this.creator), "You have to be the creator to view this item", 401);
Run Code Online (Sandbox Code Playgroud)
有关cancellUnless()和isMe()的更多信息,请访问:http://docs.deployd.com/docs/collections/reference/event-api.md#s-cancelIf%28%29,%20cancelUnless%28%29-764
保护集合的良好做法是仅在用户被记录时才允许查询:
cancelUnless(me,"You have to be connected to view this item", 401);
Run Code Online (Sandbox Code Playgroud)
用户集合应该特别安全(仅允许管理员使用ON_PUT或类似的东西).
*:要自动将currentUserId存储在creator属性中,您还可以在仪表板的ON_POST事件中添加它:
this.creator = me.id;
Run Code Online (Sandbox Code Playgroud)
更多信息:http://docs.deployd.com/docs/collections/reference/event-api.md#s-me-764
| 归档时间: |
|
| 查看次数: |
1011 次 |
| 最近记录: |