This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/routes/auth/ResetPassword.js
2022-03-30 09:46:43 -05:00

31 lines
827 B
JavaScript

const forge = require('node-forge');
const { ResetRequest } = require('../../models/index');
async function ResetPassword(req, res, next) {
reqID = req.params.id;
password = req.body.password;
if (!password) {
return res.status(400).send('Form missing required information.');
}
const result = await ResetRequest.findOne({ where: { reqID: reqID } });
if (!result) {
return res
.status(500)
.send('A reset request with this ID does not exist');
}
const hashedPassword = forge.md.sha512
.create()
.update(password)
.digest()
.toHex();
const user = await result.getUser();
await user.update({ password: hashedPassword });
return res.send('Your password has been changed');
}
module.exports = ResetPassword;