我想在我的夹具中创建用户并能够以该用户的身份登录。出于这个原因,我需要以某种方式设置用户的密码(如果我尝试登录没有密码,我得到'用户没有密码设置'验证错误)。如何设置在夹具中创建的用户的密码
到目前为止,我只有:
var joeId = Meteor.users.insert({
username: 'joe'
})
我想在我的夹具中创建用户并能够以该用户的身份登录。出于这个原因,我需要以某种方式设置用户的密码(如果我尝试登录没有密码,我得到'用户没有密码设置'验证错误)。如何设置在夹具中创建的用户的密码
到目前为止,我只有:
var joeId = Meteor.users.insert({
username: 'joe'
})
使用http://docs.meteor.com/#accounts_createuser你可以这样做:
Accounts.createUser({
'username' : 'John Doe',
'email' : '[email protected]',
'password' : 'abc123' //encrypted automatically
}, function(err){
if(typeof err === 'undefined'){
//account created successfully you might want to send an email to the user using Account.sendEnrollmentEmail()
}
});
这将在成功创建该用户登录。
流星抱怨“错误:服务器上不支持回调的Accounts.createUser。”如果试图在服务器端设备上创建用户,则为Meteor 0.6.4。
只需添加下列寻衅乔后:
Accounts.setPassword(joeId, 'my great password')