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