如何在流星种子中创建经过验证的帐户

时间:2015-10-04 17:59:40

标签: meteor meteor-accounts

我必须在播种时创建一个经过验证的帐户。以下用户对象创建user.email[0].verified = 'false'但它应该在true

user = {
  name: 'Admin',
  email: 'admin@example.com',
  password: 'password',
}
Meteor.startup(function() {
 if (Meteor.users.find().count() < 2) {
      Accounts.createUser(user); // It create user verification as false. How to make them true
 }
});

我尝试了以下对象,但没有用。

user = {
  name: 'Admin',
  email: [address:'admin@example.com',verified:true],
  password: 'password',
}

流星套餐:

accounts-password
ian:accounts-ui-bootstrap-3

1 个答案:

答案 0 :(得分:3)

似乎Accounts.addEmail允许以编程方式设置已验证的属性。根据文档,如果用户已经注册了该电子邮件,它应该覆盖这些设置。值得一试

Accounts.addEmail(userId, newEmail, [verified])

http://docs.meteor.com/#/full/Accounts-addEmail

在你的情况下(在服务器上):

user = {
  name: 'Admin',
  email: 'admin@example.com',
  password: 'password',
}
Meteor.startup(function() {
  if (Meteor.users.find().count() < 2) {
    userId = Accounts.createUser(user);
    Accounts.addEmail(userId, user.email, true);
  }
});