|
|
@ -412,22 +412,38 @@ exports.changePassword = async (req, reply) => {
|
|
|
|
// Check the result of the update operation
|
|
|
|
// Check the result of the update operation
|
|
|
|
if (updateResult.nModified > 0) {
|
|
|
|
if (updateResult.nModified > 0) {
|
|
|
|
// Fetch the updated user data (excluding password)
|
|
|
|
// 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
|
|
|
|
// Generate a new token for the user
|
|
|
|
const token = jwt.sign(
|
|
|
|
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
|
|
|
|
JWT_SECRET, // Use your secret key from environment variables
|
|
|
|
{ expiresIn: '1h' } // Token expiration time
|
|
|
|
{ expiresIn: "1h" } // Token expiration time
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
return reply.send({
|
|
|
|
simplydata: {
|
|
|
|
simplydata: {
|
|
|
|
error: false,
|
|
|
|
error: false,
|
|
|
|
passwordChanged: true,
|
|
|
|
apiversion: "1.0.0",
|
|
|
|
userData: updatedUser, // Include updated user data
|
|
|
|
access_token: token, // Include the token in the response
|
|
|
|
token, // Include the token in the response
|
|
|
|
buildingName: updatedUser.buildingName,
|
|
|
|
message: "Password updated successfully.",
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
@ -445,6 +461,7 @@ exports.changePassword = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.verifyOldNewPassword = async (req, reply) => {
|
|
|
|
exports.verifyOldNewPassword = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { phone, oldPassword, newPassword } = req.body;
|
|
|
|
const { phone, oldPassword, newPassword } = req.body;
|
|
|
|