【发布时间】:2017-09-04 22:25:00
【问题描述】:
我想拥有用户可以更改密码的功能。 我已经实现了这样的路线('/resetPasswd'):
UserRouter.route('/resetPasswd')
.post(function (req, res, next) {
passport.authenticate('local', function (err, user, info) {
user.changePassword(req.body.oldPassword, req.body.newPassword, function (err, user) {
if (err) next(err);
res.json('password changes successfully !');
})
})(req, res, next);
});
这是我发送的正文:
{
"oldpassword": "secret",
"newPassword": "new"
}
但我收到此错误作为响应:
{
"message": "user.changePassword is not a function",
"error": {}
}
这是我的架构的图片:
用户架构:
我认为我不应该在我的架构中声明 changePassword 函数(因为它是由 passport-local-mongoose 提供的,虽然我添加了它但仍然得到同样的错误)我在这里犯了什么错误?
【问题讨论】:
-
能否向我们展示您的架构和架构上的中间件(如果有)?
-
@turmuka : 我已经在帖子中提供了我的架构图片
-
@Syed Ayesha Bebe 我已经看过这篇文章,我不需要实现任何东西,因为所有功能都是由护照本身提供的。就是不知道怎么用
-
请don't put code as images。复制代码并粘贴到这里
标签: node.js mongodb authentication passport-local