使用simple schema和accounts-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'}]
没有电子邮件或密码。没有错误。思考?
此系统中的新用户只能由现有用户添加,因此我无法测试用户提交表单。
答案 0 :(得分:2)
Accounts.createUser将String作为email
参数的options
属性。至于密码问题,可能是由于模式中缺少services
属性。添加到Schemas.User
以下媒体资源:
Schemas.User = new SimpleSchema({
// ...
services: {
type: Object,
optional: true,
blackbox: true
}
}
最后,Accounts.createUser
文档(请参阅第一个链接)声明:
在客户端上,您必须传递密码以及
username
或Accounts.setPassword
设置)。
似乎不适用于您的情况,但作为最后的手段,请尝试之后致电Accounts.setPassword(userId, "mypassword")
。用户的ID由Meteor.createUser
返回。