|
|
|
@ -161,11 +161,16 @@ fastify.post("/api/login", {
|
|
|
|
|
properties: {
|
|
|
|
|
phone: { type: "string" },
|
|
|
|
|
password: { type: "string" },
|
|
|
|
|
fcmId: { type: "string" }, // Add this line
|
|
|
|
|
deviceId: { type: "string" } // Add this line
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async handler(req, reply) {
|
|
|
|
|
loginObject = await userController.loginUser(req);
|
|
|
|
|
// Pass fcmId and deviceId to the loginUser function
|
|
|
|
|
const { phone, password, fcmId, deviceId } = req.body;
|
|
|
|
|
const loginObject = await userController.loginUser(req, fcmId, deviceId);
|
|
|
|
|
|
|
|
|
|
if (loginObject.same) {
|
|
|
|
|
const phoneVerified = loginObject.user.phoneVerified;
|
|
|
|
|
const oneTimePasswordSetFlag = loginObject.user.oneTimePasswordSetFlag;
|
|
|
|
@ -180,7 +185,6 @@ fastify.post("/api/login", {
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
phoneVerified: false,
|
|
|
|
|
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
|
|
|
|
|
message: "Please Verify your phone number",
|
|
|
|
@ -203,87 +207,72 @@ fastify.post("/api/login", {
|
|
|
|
|
userId: loginObject.user._id,
|
|
|
|
|
roles: loginObject.user.profile.role,
|
|
|
|
|
},
|
|
|
|
|
//expiresIn: expressed in seconds or a string describing a time span zeit/ms. Eg: 60, "2 days", "10h", "7d".
|
|
|
|
|
//A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc),
|
|
|
|
|
//otherwise milliseconds unit is used by default ("120" is equal to "120ms").
|
|
|
|
|
{ expiresIn: "30d" }
|
|
|
|
|
);
|
|
|
|
|
var arr = loginObject.user.profile.role;
|
|
|
|
|
var arrayToString = JSON.stringify(Object.assign({}, arr)); // convert array to string
|
|
|
|
|
var stringToJsonObject = JSON.parse(arrayToString); // convert string to json object
|
|
|
|
|
var c_id = loginObject.user.customerId
|
|
|
|
|
var profilePicture = await ProfilePicture.findOne({ customerId:c_id});
|
|
|
|
|
const arr = loginObject.user.profile.role;
|
|
|
|
|
const arrayToString = JSON.stringify(Object.assign({}, arr)); // convert array to string
|
|
|
|
|
const stringToJsonObject = JSON.parse(arrayToString); // convert string to json object
|
|
|
|
|
const c_id = loginObject.user.customerId;
|
|
|
|
|
const profilePicture = await ProfilePicture.findOne({ customerId: c_id });
|
|
|
|
|
|
|
|
|
|
if (!profilePicture) {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
buildingName:loginObject.user.buildingName,
|
|
|
|
|
email: loginObject.user.emails,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
customerId: loginObject.user.customerId,
|
|
|
|
|
username: loginObject.user.username,
|
|
|
|
|
address1: loginObject.user.profile.address1,
|
|
|
|
|
address2: loginObject.user.profile.address2,
|
|
|
|
|
phoneVerified: loginObject.user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
|
|
|
|
|
latitude: loginObject.user.latitude,
|
|
|
|
|
longitude: loginObject.user.longitude,
|
|
|
|
|
type: loginObject.user.profile.role,
|
|
|
|
|
fcmId: loginObject.user.fcmId,
|
|
|
|
|
deviceId: loginObject.user.deviceId,
|
|
|
|
|
typeasobj: stringToJsonObject,
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
buildingName: loginObject.user.buildingName,
|
|
|
|
|
email: loginObject.user.emails,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
customerId: loginObject.user.customerId,
|
|
|
|
|
username: loginObject.user.username,
|
|
|
|
|
address1: loginObject.user.profile.address1,
|
|
|
|
|
address2: loginObject.user.profile.address2,
|
|
|
|
|
phoneVerified: loginObject.user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
|
|
|
|
|
latitude: loginObject.user.latitude,
|
|
|
|
|
longitude: loginObject.user.longitude,
|
|
|
|
|
type: loginObject.user.profile.role,
|
|
|
|
|
typeasobj: stringToJsonObject,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}if (profilePicture) {
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
picture:profilePicture.picture,
|
|
|
|
|
email: loginObject.user.emails,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
buildingName:loginObject.user.buildingName,
|
|
|
|
|
customerId: loginObject.user.customerId,
|
|
|
|
|
username: loginObject.user.username,
|
|
|
|
|
address1: loginObject.user.profile.address1,
|
|
|
|
|
address2: loginObject.user.profile.address2,
|
|
|
|
|
phoneVerified: loginObject.user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
|
|
|
|
|
latitude: loginObject.user.latitude,
|
|
|
|
|
longitude: loginObject.user.longitude,
|
|
|
|
|
type: loginObject.user.profile.role,
|
|
|
|
|
deviceId: loginObject.user.deviceId,
|
|
|
|
|
fcmId: loginObject.user.fcmId,
|
|
|
|
|
typeasobj: stringToJsonObject,
|
|
|
|
|
apiversion: fastify.config.APIVERSION,
|
|
|
|
|
access_token: token,
|
|
|
|
|
picture: profilePicture.picture,
|
|
|
|
|
email: loginObject.user.emails,
|
|
|
|
|
phone: loginObject.user.phone,
|
|
|
|
|
buildingName: loginObject.user.buildingName,
|
|
|
|
|
customerId: loginObject.user.customerId,
|
|
|
|
|
username: loginObject.user.username,
|
|
|
|
|
address1: loginObject.user.profile.address1,
|
|
|
|
|
address2: loginObject.user.profile.address2,
|
|
|
|
|
phoneVerified: loginObject.user.phoneVerified,
|
|
|
|
|
oneTimePasswordSetFlag: loginObject.user.oneTimePasswordSetFlag,
|
|
|
|
|
latitude: loginObject.user.latitude,
|
|
|
|
|
longitude: loginObject.user.longitude,
|
|
|
|
|
type: loginObject.user.profile.role,
|
|
|
|
|
typeasobj: stringToJsonObject,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log({
|
|
|
|
|
// username: loginObject.user.username,
|
|
|
|
|
// roles: loginObject.user.profile.role,
|
|
|
|
|
// rolesasobj: stringToJsonObject,
|
|
|
|
|
// });
|
|
|
|
|
// console.log("sending token \n");
|
|
|
|
|
// console.log(token);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
error = {
|
|
|
|
|
reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
code: 400,
|
|
|
|
|
message: "Invalid UserId , Password supplied",
|
|
|
|
|
message: "Invalid UserId or Password supplied",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
reply.send(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.post("/api/installotplogin", {
|
|
|
|
|
schema: {
|
|
|
|
|
description: "This is for Login Otp Installation",
|
|
|
|
|