reset password
Should check if can reset pass of another user
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user