From cae661a55261eba42c992205318098d7bb847b34 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 17 Jan 2025 12:18:32 +0530 Subject: [PATCH] forgot password response chnages --- src/handlers/userHandler.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/handlers/userHandler.js b/src/handlers/userHandler.js index eabf6fb1..ebbef9c0 100644 --- a/src/handlers/userHandler.js +++ b/src/handlers/userHandler.js @@ -412,22 +412,38 @@ exports.changePassword = async (req, reply) => { // Check the result of the update operation if (updateResult.nModified > 0) { // Fetch the updated user data (excluding password) - const updatedUser = await User.findOne({ phone }).select('-services.password.bcrypt'); + const updatedUser = await User.findOne({ phone }).select( + "-services.password.bcrypt" + ); // Generate a new token for the user const token = jwt.sign( - { id: updatedUser._id, phone: updatedUser.phone }, // You can include more user details if needed + { id: updatedUser._id, phone: updatedUser.phone }, // Include user details as needed JWT_SECRET, // Use your secret key from environment variables - { expiresIn: '1h' } // Token expiration time + { expiresIn: "1h" } // Token expiration time ); return reply.send({ simplydata: { error: false, - passwordChanged: true, - userData: updatedUser, // Include updated user data - token, // Include the token in the response - message: "Password updated successfully.", + apiversion: "1.0.0", + access_token: token, // Include the token in the response + buildingName: updatedUser.buildingName, + email: updatedUser.emails, + phone: updatedUser.phone, + customerId: updatedUser.customerId, + username: updatedUser.username, + address1: updatedUser.profile.address1, + address2: updatedUser.profile.address2, + phoneVerified: updatedUser.phoneVerified, + oneTimePasswordSetFlag: updatedUser.oneTimePasswordSetFlag, + latitude: updatedUser.latitude, + longitude: updatedUser.longitude, + type: updatedUser.profile.role, + typeasobj: updatedUser.profile.role.reduce((obj, role, index) => { + obj[index] = role; + return obj; + }, {}), }, }); } else { @@ -445,6 +461,7 @@ exports.changePassword = async (req, reply) => { } }; + exports.verifyOldNewPassword = async (req, reply) => { try { const { phone, oldPassword, newPassword } = req.body;