【发布时间】:2020-09-25 07:31:29
【问题描述】:
所以,我正在尝试设置我的程序,以便在确认旧密码正确后更新用户的密码。我已经得到了除一行之外的所有代码,以按照我期望的方式运行:
router.put("/:id/edit_password", isLoggedIn, isAdministrator, async function(req, res){
user = {};
try {
user = await User.findById(req.params.id)
}
catch (err) {console.log(err);}
user.authenticate(req.body.user["old_password"], async function(err, model, passwordError){
if(passwordError){
console.log("Old Password is Incorrect");
// Flash Old Password is Incorrect
res.redirect("/users/" + req.params.id + "/edit_password");
} else if (model) {
console.log("Old Password is Correct");
try {
await user.setPassword(req.body.user["new_password"]); //this line does not work
console.log("Password Changed");
}
catch (err) {console.log(err);}
res.redirect("/users/" + req.params.id);
} else
{
console.log(err);
}
});
});
其中的 await user.setPassword 部分似乎不起作用。使用 console.logs,我可以确认一切都按应有的方式进行。在这种情况下,除了 user.setPassword 之外,是否需要使用其他功能? 谢谢。
【问题讨论】:
标签: javascript node.js mongodb express passport.js