【问题标题】:Meteor-Mongodb userdata publish settingsMeteor-Mongodb 用户数据发布设置
【发布时间】:2018-06-22 02:09:13
【问题描述】:

我即将为我的学生打开一个 Meteor 网络应用程序,我显然需要将用户集合中的数据保密(每个学生都应该有权访问她自己的“结果”)。但是“管理员”角色需要拥有更多访问权限。这是发布信息(/server/main.js):

Meteor.publish('userData', function() {
    if (Roles.userIsInRole(this.userId, ['admin'])) {
        return Meteor.users.find({}, {fields: {
            _id: 1,
            createdAt: 1,
            username: 1,
            emails: 1,
            profile: 1,
            lastAccess: 1,
            roles: 1
            }}
        )};

    if (this.userId) {
        return Meteor.users.find({_id: this.userId}, {fields: {
             results: 1
            }
        });
    } else {
        this.ready();
    }
});

我的问题是:这种发布设置对于恶意用户是否足够安全?

【问题讨论】:

  • 您可以将type 密钥保存在users 集合中,并在调用方法时检查服务器端的访问/权限。在客户端,任何人都可以操作数据,但是当您从服务器端发送数据时,您可以执行必要的检查。

标签: mongodb meteor


【解决方案1】:

简短回答:


请记住,您无需发布任何集合即可检索已登录用户的数据。在客户端,您无需订阅即可使用Meteor.user()

因此,如果您想显示登录用户以外的用户信息,您只需订阅userData

另外,请记住,当您返回 Mongo 光标时,您不必调用 this.ready()

因此,您的出版物变成:

Meteor.publish('userData', function() {
    if (Roles.userIsInRole(this.userId, ['admin'])) {
        return Meteor.users.find({}, { fields: {
            _id: 1,
            createdAt: 1,
            username: 1,
            emails: 1,
            profile: 1,
            lastAccess: 1,
            roles: 1
        }});
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 2014-06-05
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多