在我的nodejs中,我定义了一条路线
router.post('/change-password/:id', (req, res) => {
User.findOneAndUpdate({
username: req.params.id
}, {
password: req.body.password
}).then(update => {
if (update) {
return res.status(200).json({
message: 'Password changed!'
});
} else {
return res.status(401).json({
message: 'Invalid Request'
});
}
})
});
1)我想确定newUser是否已登录,然后他们首先进入个人资料页面并更改密码
),因此在创建新帐户时,用户将重定向到要求他们更改密码的页面。在我的模型中,我有一个字段newUser:Boolean
,并且在创建用户帐户时将其设置为true
。我只想确保用户已更改密码,并且除非他们更改密码,否则他们不能手动更改URL。在他们更改密码后,我可以将该字段设置为false
这是我的routing.model.ts
{
path: "change-password/:name",
component: profilePageComponent,
canActivate: [AuthGuard]
},
当然,changePassword具有用于更改密码的表单域。