changes in login for staff

master^2
Varun 7 months ago
parent cd505dcab4
commit c6055ac5ca

@ -289,6 +289,7 @@ exports.loginUser = async (req, fcmIds, deviceId) => {
// If not a main user, check staff inside all users // If not a main user, check staff inside all users
if (!user) { if (!user) {
const users = await User.find({ "staff.staff.phone": phone }); const users = await User.find({ "staff.staff.phone": phone });
for (const u of users) { for (const u of users) {
const foundStaff = u.staff.staff.find((s) => s.phone === phone); const foundStaff = u.staff.staff.find((s) => s.phone === phone);
@ -301,7 +302,6 @@ exports.loginUser = async (req, fcmIds, deviceId) => {
} }
} }
// If no user or staff found, return invalid credentials // If no user or staff found, return invalid credentials
if (!user) return { same: false }; if (!user) return { same: false };
@ -324,6 +324,9 @@ exports.loginUser = async (req, fcmIds, deviceId) => {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
exports.loginUserWithOTP = async (req) => { exports.loginUserWithOTP = async (req) => {
try { try {
const phone = req.body.phone; const phone = req.body.phone;

@ -202,7 +202,7 @@ fastify.post("/api/login", {
simplydata: { simplydata: {
error: false, error: false,
phoneVerified: false, phoneVerified: false,
phone: user.phone, phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone,
oneTimePasswordSetFlag, oneTimePasswordSetFlag,
message: "Please Verify your phone number", message: "Please Verify your phone number",
}, },
@ -214,7 +214,7 @@ fastify.post("/api/login", {
simplydata: { simplydata: {
error: false, error: false,
phoneVerified, phoneVerified,
phone: user.phone, phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone,
oneTimePasswordSetFlag: true, oneTimePasswordSetFlag: true,
message: "Password must be reset", message: "Password must be reset",
}, },
@ -237,7 +237,7 @@ fastify.post("/api/login", {
access_token: token, access_token: token,
buildingName: user.buildingName, buildingName: user.buildingName,
email: user.emails, email: user.emails,
phone: user.phone, phone: loginObject.isStaff ? loginObject.staffMember.phone : user.phone,
customerId: user.customerId, customerId: user.customerId,
username: loginObject.isStaff ? loginObject.staffMember.name : user.username, username: loginObject.isStaff ? loginObject.staffMember.name : user.username,
address1: user.profile.address1, address1: user.profile.address1,
@ -251,7 +251,10 @@ fastify.post("/api/login", {
}, },
}; };
if (loginObject.isStaff) {
responsePayload.simplydata.all_motor_access = loginObject.staffMember.all_motor_access;
}
if (profilePicture) { if (profilePicture) {
responsePayload.simplydata.picture = profilePicture.picture; responsePayload.simplydata.picture = profilePicture.picture;
} }
@ -263,6 +266,7 @@ fastify.post("/api/login", {
fastify.post("/api/installotplogin", { fastify.post("/api/installotplogin", {
schema: { schema: {
description: "This is for Login Otp Installation", description: "This is for Login Otp Installation",

Loading…
Cancel
Save