From 8776401d865e07e45eba82cf6ffd11a788015cfc Mon Sep 17 00:00:00 2001 From: patrickjieraldjuan Date: Sun, 28 Jan 2024 11:11:15 +0800 Subject: [PATCH] Added controller and route for reset password --- controllers/userControllers.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/controllers/userControllers.js b/controllers/userControllers.js index d711fde..9216cb4 100644 --- a/controllers/userControllers.js +++ b/controllers/userControllers.js @@ -137,4 +137,27 @@ module.exports.getAllOrders = async (req, res) => { console.error(error); res.status(500).json({ message: 'Error retrieving Orders' }); } +}; + + +// reset password controller +module.exports.resetPassword = async (req, res) => { + try { + // Get user ID from the JWT token passed in the authorization headers + const userId = req.user.id; + + // Get the new password from the request body + const { newPassword } = req.body; + + // Hash the new password + const hashedPassword = await bcrypt.hash(newPassword, 10); + + // Update the user's password in the database + await User.findByIdAndUpdate(userId, { password: hashedPassword }); + + res.status(200).json(true); + } catch (error) { + console.error(error); + res.status(500).json(false); + } }; \ No newline at end of file