Meteor用户没有电子邮件地址

时间:2015-05-07 14:37:07

标签: meteor schema meteor-accounts

使用simple schemaaccounts-password。我正在尝试在启动时添加初始帐户,但电子邮件和密码没有出现。

Schemas.User = new SimpleSchema({
  username: {
    type: String,
    regEx: /^[a-z0-9A-Z_]{3,15}$/
  },
  emails: {
    type: [Object],
    optional: true
  },
  "emails.$.address": {
    type: String,
    regEx: SimpleSchema.RegEx.Email
  },
  "emails.$.verified": {
    type: Boolean
  },
  profile: {
    type: Schemas.UserProfile,
    optional: true
  }
});

Meteor.startup(function () {
  Meteor.users.remove({});
  if (Meteor.users.find().count() == 0) {
    Accounts.createUser({
      username: "newuser",
      emails: [{address:"test@test.com", verified:true}],
      password:"mypassword"
    });
  }
  console.log(Meteor.users.find().fetch());
}

给我们:

[{_id: 'xxx', username:'newuser'}]

没有电子邮件或密码。没有错误。思考?

此系统中的新用户只能由现有用户添加,因此我无法测试用户提交表单。

1 个答案:

答案 0 :(得分:2)

Accounts.createUser将String作为email参数的options属性。至于密码问题,可能是由于模式中缺少services属性。添加到Schemas.User以下媒体资源:

Schemas.User = new SimpleSchema({
  // ...
  services: {
      type: Object,
      optional: true,
      blackbox: true
  }
}

最后,Accounts.createUser文档(请参阅第一个链接)声明:

  

在客户端上,您必须传递密码以及usernameemail中的至少一个 - 足够的信息,以便用户以后能够再次登录。在服务器上,您不需要指定密码,但用户在拥有密码之前将无法登录(例如,使用Accounts.setPassword设置)。

似乎不适用于您的情况,但作为最后的手段,请尝试之后致电Accounts.setPassword(userId, "mypassword")。用户的ID由Meteor.createUser返回。