简体   繁体   English

服务器端数据在Meteor中提交

[英]Server-side data submit in Meteor

I am new to meteor.Iam using meteor aldeed autoform and collection2 packages in my app.here is my client js file. 我是流星新手,我在我的应用程序中使用流星aldeed autoform和collection2包。这是我的客户端js文件。

Schema = {};

Schema.dc_address = new SimpleSchema({

 'dataCenterName': {
    type: String,
    index: 1,
    label:'Name of the Provider',
    regEx: /^[a-zA-Z\s]+$/
  },
'address1': {
    type: String,
    index: 1,
    label:'Address Line 1',
    regEx: /^[a-zA-Z0-9\s]+$/
  },
'address2': {
    type: String,
    index: 1,
    label:'Address Line 2',
    regEx: /^[a-zA-Z0-9\s]+$/
  },

});


  Template.dataCenters.helpers({//dataCenters is my main template
    steps: function() {
      return [{
        id: 'dc_address',
        title: 'Name & Address',
        template: 'dc_address',
        formId: 'dc_address_form',
        onSubmit: function(data, wizard) {



        var params=_.extend(wizard.mergedData(), data);
        alert(params);

     var jsonrpc = new $.JsonRpcClient({ ajaxUrl: 'http://172.16.4.190:8384' });


        jsonrpc.call(
                 'dataCenterCreate', params,
                     function(result) {alert('Pizzeria answered: ' + $.toJSON(result)); },
                    function(error)  { console.log('There was an error', $.toJSON(error)); }
            );

        }
      }];
    }
  });

here is my html page 这是我的html页面

<template name="dc_address">
<div class="form-wrapper">
  {{#autoForm doc=this.data id="dc_address_form"  schema=Schema.dc_address }}
    <div class="col-md-12">
        {{> afQuickField name="dataCenterName" placeholder="Enter DataCenter Name"}}
    </div>  
    <table>
    <tr>
    <td class="col-md-6">
    {{> afQuickField name="address1" placeholder="#7 4th cross"}}
    </td>
    <div class="col-md-1"></div>
    <td class="col-md-6">   
    {{> afQuickField name="address2" placeholder="ITPL-banglore"}}
    </td>
    </tr>

    <button type="submit" class="btn btn-success btn-md pull-right">Next</button>

  {{/autoForm}}
  </div>
</template>

That works pretty well although - it's CLIENT side submit => it is not secure. 尽管效果很好-尽管它是客户端提交的,但它并不安全。 How do I implement it is in server side? 如何在服务器端实现它?

For security you should remove autopublish and insecure packages. 为了安全起见,您应该删除自动发布和不安全的软件包。 Once you do this inserting anything into the databases will throw an error. 完成此操作后,将任何内容插入数据库都将引发错误。 Try Posts.insert({}) in the console to see the errors appear. 在控制台中尝试Posts.insert({})来查看错误。

You get around this by adding allow and deny rules on your server (see the meteor docs for more on allow/deny rules). 您可以通过在服务器上添加“允许和拒绝”规则来解决此问题(有关“允许/拒绝”规则的更多信息,请参阅流星文档)。 You can also use meteor methods using: Meteor.call(...) to insert docs into the database without having any allow rules set up. 您还可以使用以下流星方法:Meteor.call(...)将docs插入数据库而无需设置任何允许规则。 You'd have to do your own checks within the meteor method in this case. 在这种情况下,您必须在流星方法中进行自己的检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM