[英]Server-side data validation in Meteor
我的客戶端文件中有一個表單和一個提交功能:
function submitme () {
var message = $('#daform').serializeJSON();
message.owner = Meteor.user().username;
if(!message.description || !message.location.lat || !message.location.lng || !message.mysex || !message.yoursex) {
return;
}
else
{
lists.insert(message);
console.log("Submitted!");
$('#daform')[0].reset();
}
}
盡管效果很好-盡管這是客戶端驗證=>不安全。
如何在服務器文件中實施“備份”驗證檢查? (+獎勵問題:如何設置計時器,以便在提交后需要等待X秒才能重新提交?)
您可以使用http://docs.meteor.com/#deny (您可以使用allow,但是將驗證內容放在單獨的deny中可能會更容易),因為在不應插入的情況下deny會覆蓋allow:
它只是在插入服務器之前作為服務器上的備份方法。
與您的留言集
服務器Js
message.deny({
insert: function (userId, doc) {
return (!doc.description || !doc.location.lat || !doc.location.lng || !doc.mysex || !doc.yoursex);
},
update: function (userId, docs, fields, modifier) {
return (!doc.description || !doc.location.lat || !doc.location.lng || !doc.mysex || !doc.yoursex);
}
);
注意 :從拒絕返回false表示不拒絕。 要拒絕更新,您必須返回true。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.