【问题标题】:Insert using Autoform with insecure removed使用 Autoform 插入并删除不安全
【发布时间】:2015-02-01 14:26:37
【问题描述】:

我一直在我的 Meteor 项目中使用 Collection2 和 Autoform,这让事情变得容易多了!

但是,当我删除不安全时,它不再插入(自动提交按钮)。这是我预料到的!

但是,我进行了搜索,但找不到使其正常工作的标准方法?我在 lib 文件夹中定义了一个模式,并且我的 Autoform 作为模板中的快速表单。我知道我需要允许客户端插入(我不想这样做)或将其传输到服务器端(可能带有方法?)

任何建议将不胜感激!我正在寻找实现它的标准方法。

【问题讨论】:

  • 是的,我已经附加了 Schema,但由于某种原因它在不安全的情况下无法正常工作。作者在这里提到,如果关闭不安全,您必须定义自己的允许/拒绝规则:github.com/aldeed/meteor-autoform/issues/380

标签: javascript meteor schema meteor-autoform


【解决方案1】:

经过大量挖掘找到了我自己的答案。为插入、更新和删除创建了允许规则:

Posts = new Mongo.Collection('posts');

//SECURITY - Allow Callbacks for posting

Posts.allow({
  insert: function(userId, doc) {
    // only allow posting if you are logged in
    return !! userId; 
  },
  update: function(userId, doc) {
    // only allow updating if you are logged in
    return !! userId; 
  },
  remove: function(userID, doc) {
    //only allow deleting if you are owner
    return doc.submittedById === Meteor.userId();
  }
});

//Schema then defined as usual

请注意,submitById 是我的集合中保留 userId 的字段。如果您将其称为不同的名称,请更改它!

希望这对遇到类似问题的人有所帮助。

【讨论】:

  • 谢谢,这对我有帮助!另外,我将此允许/拒绝代码放在共享(客户端/服务器)文件夹中。
猜你喜欢
  • 2015-11-05
  • 2022-08-05
  • 2011-05-01
  • 2011-04-30
  • 2017-11-25
  • 2020-07-22
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
相关资源
最近更新 更多