此Meteor应用删除了不安全和自动发布的内容,并添加了帐户密码。
它使用Accounts.createUser({username: someName, password: somePwrd}); 可以在mongo提示符下进行验证的内容。
我正在尝试Tasks1.insert(params);并拒绝访问
我不知道为什么它会拒绝Access进行更新并在浏览器控制台上插入。请告诉我原因以及如何解决?谢谢
//both.js
Tasks1 = new Mongo.Collection('tasks1');
/////////////////////////////////////////////////////
//server.js
Meteor.publish('tasks1', function(){
return Tasks1.find({userId: this.userId});
});
Meteor.methods({
logMeIn: function(credentials) {
var idPin = credentials[0] + credentials[1];
Accounts.createUser({username: idPin, password: credentials[1]});
}
});
Meteor.users.allow({
insert: function (userId, doc) {
console.log(userId);
//var u = Meteor.users.findOne({_id:userId});
return true;
}
});
/////////////////////////////////////////////////////
//client.js
Template.login.events({
'click #logMe': function() {
var credentials = [$('#id').val(), $('#pin').val()];
Meteor.call('logMeIn', credentials, function(err, result) {
if (result) {
console.log('logged in!');
}
});
}
});
Template.footer.events({
'click button': function () {
if ( this.text === "SUBMIT" ) {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var params = {};
params[inputs[i].name] = inputs[i].value;
Tasks1.insert(params); //<<<<<<----------------------
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
由于您已经编辑了问题并添加了“ Tasks1.insert(params);拒绝访问”消息,因此应allow在Tasks收集而非Meteor.users收集上添加规则。
Tasks.allow({
insert: function (userId, doc) {
return true;
},
update: function (userId, doc, fieldNames, modifier) {
return true;
},
remove: function (userId, doc) {
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
如果Accounts.createUser没有allow规则,Meteor.users请删除它们,因为它可能允许用户从客户端本身插入/删除其他用户。
更新结束。
自从删除以来insecure,您需要添加allow/deny用于从集合中插入,更新或删除文件的规则。
Meteor.users.allow({
insert: function (userId, doc) {
//Normally I would check if (this.userId) to see if the method is called by logged in user or guest
//you can also add some checks here like user role based check etc.,
return true;
},
update: function (userId, doc, fieldNames, modifier) {
//similar checks like insert
return true;
},
remove: function (userId, doc) {
//similar checks like insert
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
查看API文档以了解更多详细信息。
| 归档时间: |
|
| 查看次数: |
2800 次 |
| 最近记录: |