我上面的代碼運行沒有任何錯誤,但沒有保存新密碼。
我一直在關注 bcrypt檔案、一篇博客文章和一段視頻,并認為這三種不同的來源導致我遺漏了一些重要的東西。任何想法為什么沒有保存新密碼?
module.exports.submitNewPassword = async (req, res) => {
const slidedHeaderToken = req.headers.referer.slice(-40);
const artist = await Artist.find({ resetPasswordToken: slidedHeaderToken, resetPasswordExpires: { $gt: Date.now() } });
if (!artist) {
console.log("Artist doesn't exist");
} else {
const hashedPassword = async (pw) => {
bcrypt.hash(req.body.password, 12)
}
hashedPassword()
artist.password = hashedPassword;
resetPasswordToken = null;
resetPasswordExpires = null;
console.log("Successfully resubmitted password");
res.redirect('login');
}
}
uj5u.com熱心網友回復:
await artist.save()設定某些欄位后,您應該呼叫函式
uj5u.com熱心網友回復:
當您使用 更改資料Find時,您需要save它。
await yourModel.save()
uj5u.com熱心網友回復:
artists是與呼叫中的引數匹配的所有藝術家的陣列.find()。如果您只想找到一個,請使用.findOne().
然后在修改后,使用.save()將其保存回資料庫。
module.exports.submitNewPassword = async (req, res) => {
const slidedHeaderToken = req.headers.referer.slice(-40);
const artist = await Artist.findOne({ resetPasswordToken: slidedHeaderToken, resetPasswordExpires: { $gt: Date.now() } });
if (!artist) {
console.log("Artist doesn't exist");
} else {
const hashedPassword = async (pw) => {
bcrypt.hash(req.body.password, 12)
}
hashedPassword()
artist.password = hashedPassword;
await artist.save();
resetPasswordToken = null;
resetPasswordExpires = null;
console.log("Successfully resubmitted password");
res.redirect('login');
}
}
請參閱此處的 Mongoose 教程。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/484038.html
標籤:javascript 节点.js 猫鼬 密码 bcrypt
