reset password

Should check if can reset pass of another user
This commit is contained in:
2020-09-12 20:47:41 +02:00
parent 4d2d62d777
commit cec24fa01a
9 changed files with 160 additions and 73 deletions

View File

@@ -26,7 +26,7 @@ var agileAPI = new AgileCRMManager(CRM_USER, CRM_KEY, CRM_EMAIL);
router.post("/login", async (req, res) => {
try {
if (!req.body.password || !req.body.email) {
throw newError("No input data", 204);
throw newError("Niepełne dane.", 204);
}
const user = await fetchUser(req.body.email);
await checkPassword(req.body.password, user.password);
@@ -56,7 +56,7 @@ router.post("/register", async (req, res) => {
router.post("/changepass", async (req, res) => {
try {
if (!req.body.password || !req.body.email || !req.body.newPass) {
throw newError("No input data", 204);
throw newError("Niepełne dane.", 204);
}
const token = req.headers["x-auth-token"];
validateUserToken(token);
@@ -64,7 +64,7 @@ router.post("/changepass", async (req, res) => {
await checkPassword(req.body.password, user.password);
const newPassword = await hashPass(req.body.newPass);
await changeUserPass(user._id, newPassword);
res.status(200).send("Password changed");
res.status(200).send("Hasło zostało zmienione.");
} catch (error) {
handleError(error, res);
}
@@ -83,5 +83,17 @@ router.post("/forgotpassword", async (req, res) => {
});
// RESET PASS
router.post("/resetpass", async (req, res) => {
try {
validateUserToken(req.body.token);
const user = await fetchUser(req.body.email);
const newPassword = await hashPass(req.body.newPass);
await changeUserPass(user._id, newPassword);
res.send("Hasło zostało zmienione.");
} catch (error) {
console.log(error);
handleError(error, res);
}
});
export default router;