【问题标题】:Meteor user has no email addressMeteor 用户没有电子邮件地址
【发布时间】:2015-05-08 00:04:31
【问题描述】:

使用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'}]

没有电子邮件或密码。没有错误。想法?

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

【问题讨论】:

  • Accounts.createUserString 作为第二个参数,而不是数组。只需将电子邮件作为字符串给它,然后验证它。
  • 抱歉,不是参数,email 属性为 options 参数
  • @BraveKenny 对电子邮件有效,但现在我在尝试登录时遇到“未设置密码”错误

标签: meteor schema meteor-accounts


【解决方案1】:

Accounts.createUser 将字符串作为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返回。

【讨论】:

  • 错误:架构不允许 services.password.srp
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2015-08-30
相关资源
最近更新 更多