|  |  |  | @ -462,74 +462,74 @@ exports.changePassword = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | exports.verifyOldNewPassword = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
		
			
				
					|  |  |  |  |     const { phone, oldPassword, newPassword } = req.body; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Check if the user exists with the provided mobile number
 | 
			
		
	
		
			
				
					|  |  |  |  |     const user = await User.findOne({ phone }); | 
			
		
	
		
			
				
					|  |  |  |  |     if (!user) { | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.send({ | 
			
		
	
		
			
				
					|  |  |  |  |         armintatankdata: { | 
			
		
	
		
			
				
					|  |  |  |  |           error: true, | 
			
		
	
		
			
				
					|  |  |  |  |           code: 10009, | 
			
		
	
		
			
				
					|  |  |  |  |           message: "User not found.", | 
			
		
	
		
			
				
					|  |  |  |  |         }, | 
			
		
	
		
			
				
					|  |  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Verify the old password
 | 
			
		
	
		
			
				
					|  |  |  |  |     const isOldPasswordCorrect = await bcrypt.compare(oldPassword, user.services.password.bcrypt); | 
			
		
	
		
			
				
					|  |  |  |  |     if (!isOldPasswordCorrect) { | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.send({ | 
			
		
	
		
			
				
					|  |  |  |  |         armintatankdata: { | 
			
		
	
		
			
				
					|  |  |  |  |           error: true, | 
			
		
	
		
			
				
					|  |  |  |  |           code: 10012, | 
			
		
	
		
			
				
					|  |  |  |  |           message: "Old password is incorrect.", | 
			
		
	
		
			
				
					|  |  |  |  |         }, | 
			
		
	
		
			
				
					|  |  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Hash the new password
 | 
			
		
	
		
			
				
					|  |  |  |  |     const hashedNewPassword = await bcrypt.hash(newPassword, 10); // Ensure you use bcrypt.hash here
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Update the password in the database
 | 
			
		
	
		
			
				
					|  |  |  |  |     const updateResult = await User.updateOne( | 
			
		
	
		
			
				
					|  |  |  |  |       { phone }, | 
			
		
	
		
			
				
					|  |  |  |  |       { | 
			
		
	
		
			
				
					|  |  |  |  |         $set: { | 
			
		
	
		
			
				
					|  |  |  |  |           "services.password.bcrypt": hashedNewPassword, | 
			
		
	
		
			
				
					|  |  |  |  |           oneTimePasswordSetFlag: false, | 
			
		
	
		
			
				
					|  |  |  |  |         }, | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  |  |     ); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Check if the update was successful
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (updateResult.nModified > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |       // Fetch the updated user details to send back in the response
 | 
			
		
	
		
			
				
					|  |  |  |  |       const updatedUser = await User.findOne({ phone }).select('-services.password.bcrypt'); // Exclude the password
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.send({ | 
			
		
	
		
			
				
					|  |  |  |  |         armintatankdata: { | 
			
		
	
		
			
				
					|  |  |  |  |           error: false, | 
			
		
	
		
			
				
					|  |  |  |  |           message: "Password changed successfully.", | 
			
		
	
		
			
				
					|  |  |  |  |           updatedUser, // Include the updated user details
 | 
			
		
	
		
			
				
					|  |  |  |  |         }, | 
			
		
	
		
			
				
					|  |  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  |  |     } else { | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.send({ | 
			
		
	
		
			
				
					|  |  |  |  |         armintatankdata: { | 
			
		
	
		
			
				
					|  |  |  |  |           error: true, | 
			
		
	
		
			
				
					|  |  |  |  |           code: 10011, | 
			
		
	
		
			
				
					|  |  |  |  |           message: "Failed to update the password. Try again.", | 
			
		
	
		
			
				
					|  |  |  |  |         }, | 
			
		
	
		
			
				
					|  |  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |   } catch (err) { | 
			
		
	
		
			
				
					|  |  |  |  |     console.error("Error in changePassword:", err); | 
			
		
	
		
			
				
					|  |  |  |  |     throw boom.boomify(err); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | // exports.verifyOldNewPassword = async (req, reply) => {
 | 
			
		
	
		
			
				
					|  |  |  |  | //   try {
 | 
			
		
	
		
			
				
					|  |  |  |  | //     const { phone, oldPassword, newPassword } = req.body;
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //     // Check if the user exists with the provided mobile number
 | 
			
		
	
		
			
				
					|  |  |  |  | //     const user = await User.findOne({ phone });
 | 
			
		
	
		
			
				
					|  |  |  |  | //     if (!user) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //       return reply.send({
 | 
			
		
	
		
			
				
					|  |  |  |  | //         armintatankdata: {
 | 
			
		
	
		
			
				
					|  |  |  |  | //           error: true,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           code: 10009,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           message: "User not found.",
 | 
			
		
	
		
			
				
					|  |  |  |  | //         },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       });
 | 
			
		
	
		
			
				
					|  |  |  |  | //     }
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //     // Verify the old password
 | 
			
		
	
		
			
				
					|  |  |  |  | //     const isOldPasswordCorrect = await bcrypt.compare(oldPassword, user.services.password.bcrypt);
 | 
			
		
	
		
			
				
					|  |  |  |  | //     if (!isOldPasswordCorrect) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //       return reply.send({
 | 
			
		
	
		
			
				
					|  |  |  |  | //         armintatankdata: {
 | 
			
		
	
		
			
				
					|  |  |  |  | //           error: true,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           code: 10012,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           message: "Old password is incorrect.",
 | 
			
		
	
		
			
				
					|  |  |  |  | //         },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       });
 | 
			
		
	
		
			
				
					|  |  |  |  | //     }
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //     // Hash the new password
 | 
			
		
	
		
			
				
					|  |  |  |  | //     const hashedNewPassword = await bcrypt.hash(newPassword, 10); // Ensure you use bcrypt.hash here
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //     // Update the password in the database
 | 
			
		
	
		
			
				
					|  |  |  |  | //     const updateResult = await User.updateOne(
 | 
			
		
	
		
			
				
					|  |  |  |  | //       { phone },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       {
 | 
			
		
	
		
			
				
					|  |  |  |  | //         $set: {
 | 
			
		
	
		
			
				
					|  |  |  |  | //           "services.password.bcrypt": hashedNewPassword,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           oneTimePasswordSetFlag: false,
 | 
			
		
	
		
			
				
					|  |  |  |  | //         },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       }
 | 
			
		
	
		
			
				
					|  |  |  |  | //     );
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //     // Check if the update was successful
 | 
			
		
	
		
			
				
					|  |  |  |  | //     if (updateResult.nModified > 0) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //       // Fetch the updated user details to send back in the response
 | 
			
		
	
		
			
				
					|  |  |  |  | //       const updatedUser = await User.findOne({ phone }).select('-services.password.bcrypt'); // Exclude the password
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //       return reply.send({
 | 
			
		
	
		
			
				
					|  |  |  |  | //         armintatankdata: {
 | 
			
		
	
		
			
				
					|  |  |  |  | //           error: false,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           message: "Password changed successfully.",
 | 
			
		
	
		
			
				
					|  |  |  |  | //           updatedUser, // Include the updated user details
 | 
			
		
	
		
			
				
					|  |  |  |  | //         },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       });
 | 
			
		
	
		
			
				
					|  |  |  |  | //     } else {
 | 
			
		
	
		
			
				
					|  |  |  |  | //       return reply.send({
 | 
			
		
	
		
			
				
					|  |  |  |  | //         armintatankdata: {
 | 
			
		
	
		
			
				
					|  |  |  |  | //           error: true,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           code: 10011,
 | 
			
		
	
		
			
				
					|  |  |  |  | //           message: "Failed to update the password. Try again.",
 | 
			
		
	
		
			
				
					|  |  |  |  | //         },
 | 
			
		
	
		
			
				
					|  |  |  |  | //       });
 | 
			
		
	
		
			
				
					|  |  |  |  | //     }
 | 
			
		
	
		
			
				
					|  |  |  |  | //   } catch (err) {
 | 
			
		
	
		
			
				
					|  |  |  |  | //     console.error("Error in changePassword:", err);
 | 
			
		
	
		
			
				
					|  |  |  |  | //     throw boom.boomify(err);
 | 
			
		
	
		
			
				
					|  |  |  |  | //   }
 | 
			
		
	
		
			
				
					|  |  |  |  | // };
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |