在 Meteor 中为用户设置新密码
set a new password to a user in Meteor
这就是我想要做的,
当用户链接社交帐户时,会创建用户,但我希望让用户提交密码,以允许他在没有电子邮件和密码的情况下登录。
我创建了一个允许用户提交密码的表单,但我找不到正确的使用方法,唯一可用的方法是
Accounts.changePassword(currentPassword, newPassword, function(error) {
if (error) {
message = 'There was an issue: ' + error.reason;
} else {
message = 'You reset your password!'
}
});
此方法的问题是我不知道用户的当前密码,他还没有密码,但当我调用 Meteor.user() 时用户仍然存在。
有什么建议吗?
您可以轻松完成以下操作。
if (Meteor.isServer) {
Meteor.startup(function () {
Accounts.setPassword("theUserId", "theNewPassword")
});
}
或使用meteor.methods
(未经测试的代码)
//server
Meteor.methods({
changePAssword:function(userId.newPassword){
Accounts.setPassword(userId, newPassword)
}
})
//client
Meteor.call('changePAssword',this.userId,newPasswordVariable,function(err,result){
if(!err){
console.log("Congrats you change the password")
}else{
console.log("pup there is an error caused by " + err.reason)
}
})
这就是我想要做的, 当用户链接社交帐户时,会创建用户,但我希望让用户提交密码,以允许他在没有电子邮件和密码的情况下登录。
我创建了一个允许用户提交密码的表单,但我找不到正确的使用方法,唯一可用的方法是
Accounts.changePassword(currentPassword, newPassword, function(error) {
if (error) {
message = 'There was an issue: ' + error.reason;
} else {
message = 'You reset your password!'
}
});
此方法的问题是我不知道用户的当前密码,他还没有密码,但当我调用 Meteor.user() 时用户仍然存在。
有什么建议吗?
您可以轻松完成以下操作。
if (Meteor.isServer) {
Meteor.startup(function () {
Accounts.setPassword("theUserId", "theNewPassword")
});
}
或使用meteor.methods
(未经测试的代码)
//server
Meteor.methods({
changePAssword:function(userId.newPassword){
Accounts.setPassword(userId, newPassword)
}
})
//client
Meteor.call('changePAssword',this.userId,newPasswordVariable,function(err,result){
if(!err){
console.log("Congrats you change the password")
}else{
console.log("pup there is an error caused by " + err.reason)
}
})