1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:39:28 +00:00

Added route for POST change password

This commit is contained in:
2022-02-14 10:33:50 +00:00
parent 51897544bf
commit 1f1a150f9c

View File

@@ -180,6 +180,42 @@ router.get('/password-reset/:uuid/:token', async (req, res) => {
});
});
router.post('/change-password', async (req, res) => {
let fields;
try {
fields = validator.validate(req.body,
[
'password',
'confPassword',
'uuid',
'token'
],
{
password: [ 'password', 'confPassword' ]
}
).fields;
} catch (e) {
console.error(e);
return res.redirect('/password-reset');
}
let pr;
try {
pr = await new PasswordReset(
fields.get('uuid'),
fields.get('token')
);
} catch(e) {
console.error(e);
return res.redirect('/password-reset');
}
const u = await pr.user;
await u.changePassword(fields.get('password'));
return res.redirect('/login');
});
module.exports = {
root: '/',
router: router