如何使用meteor帐户和autoform添加/编辑用户

如何使用meteor帐户和autoform添加/编辑用户,meteor,iron-router,meteor-accounts,meteor-autoform,Meteor,Iron Router,Meteor Accounts,Meteor Autoform,我正在Meteor中构建一个管理系统的一部分,允许管理员添加/编辑其他管理员。我正在使用Meteor帐户和Autoform,但我不知道如何处理它,因此用户可以使用Autoform进行验证并正确保存。从我发现的情况来看,似乎我需要使用Accounts.createUser方法,并将表单设置为type=“method”或其他形式,但我不确定如何处理,或者这是否是正确的方法 这是我现在的代码: 模式: Schema = {}; Schema.UserProfile = new SimpleSchem

我正在Meteor中构建一个管理系统的一部分,允许管理员添加/编辑其他管理员。我正在使用Meteor帐户和Autoform,但我不知道如何处理它,因此用户可以使用Autoform进行验证并正确保存。从我发现的情况来看,似乎我需要使用Accounts.createUser方法,并将表单设置为
type=“method”
或其他形式,但我不确定如何处理,或者这是否是正确的方法

这是我现在的代码:

模式:

Schema = {};

Schema.UserProfile = new SimpleSchema({
    name: {
        type: String,
        label: "Name"
    }
});

Schema.User = new SimpleSchema({
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    password: {
      type: String,
      label: "Password",
      min: 6
    },
    passwordConfirmation: {
      type: String,
      min: 6,
      label: "Password Confirmation",
      custom: function() {
        if (this.value !== this.field('password').value) {
          return "passwordMissmatch";
        }
      }
    },
    createdAt: {
      type: Date,
      autoValue: function() {
        if (this.isInsert) {
          return new Date;
        } else if (this.isUpsert) {
          return {$setOnInsert: new Date};
        } else {
          this.unset();
        }
      }
    },
    profile: {
        type: Schema.UserProfile
    },
    services: {
        type: Object,
        optional: true,
        blackbox: false
    }
});

Meteor.users.attachSchema(Schema.User);
路线:

Router.route('/admin/admins', {
    controller: 'AdminController',
  name: 'adminAdmins',
  title: 'Admins',
  parent: 'adminHome',
});

Router.route('/admin/admins/new', {
    controller: 'AdminController',
    name: 'adminAdminNew',
    title: 'New Admin',
    parent: 'adminAdmins',
});

Router.route('/admin/admins/:_id/edit', {
    controller: 'AdminController',
  name: 'adminAdminEdit',
  title: 'Edit Admin',
    parent: 'adminAdmins',
    data: function() {
        return Meteor.users.findOne(this.params._id);
    }
});
管理表格:

{{#autoForm collection="Meteor.users" doc=this id="adminAdminForm" type=formType}}

    {{> afQuickField name='profile.name'}}
    {{> afQuickField name='email'}}
    {{> afQuickField name='password'}}
    {{> afQuickField name='passwordConfirmation'}}

    <button type="submit" class="btn btn-block btn-secondary">Save Changes</button>
{{/autoForm}}
{{{#autoForm collection=“Meteor.users”doc=this id=“adminAdminForm”type=formType}
{{>afQuickField name='profile.name'}
{{>afQuickField name='email'}
{{>afQuickField name='password'}
{{>afquickfieldname='passwordConfirmation'}
保存更改
{{/autoForm}

您应该添加挂钩,以便能够修改集合 应该是这样的

AutoForm.hooks({
  adminAdminForm: {
    onSubmit: function (doc) {
        schemas.User.clean(doc);
        this.done();
        return false;
    },
    onSuccess:function(operation, result, template){
        Router.go('users.show',{'username':template.data.doc.username});
    },
    onError: function(operation, error, template) {
        console.log(operation,error)
    }
  }
});
您可以在专用文档中找到更多详细信息