|
|
@ -146,18 +146,18 @@ module.exports.resetPassword = async (req, res) => {
|
|
|
|
// Get user ID from the JWT token passed in the authorization headers
|
|
|
|
// Get user ID from the JWT token passed in the authorization headers
|
|
|
|
const userId = req.user.id;
|
|
|
|
const userId = req.user.id;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the old and new passwords from the request body
|
|
|
|
// Get the new password from the request body
|
|
|
|
const { oldPassword, newPassword } = req.body;
|
|
|
|
const { newPassword } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch the user from the database
|
|
|
|
User.findOne({email : req.user.email}).then(result =>
|
|
|
|
const user = await User.findById(userId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the old password is equal to the new password
|
|
|
|
const isPasswordEqualtoOld = bcrypt.compareSync(newPassword, result.password);
|
|
|
|
const isOldPasswordEqual = await bcrypt.compare(oldPassword, user.password);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isOldPasswordEqual) {
|
|
|
|
if(isPasswordEqualtoOld){
|
|
|
|
return res.status(400).json({ error: "Old password should not be equal to the new password." });
|
|
|
|
|
|
|
|
}
|
|
|
|
return response.send({message: "New password should not be same with old password"});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Hash the new password
|
|
|
|
// Hash the new password
|
|
|
|
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
|
|
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
|
|