|
|
@ -2,8 +2,14 @@ const boom = require("boom");
|
|
|
|
const bcrypt = require('bcrypt');
|
|
|
|
const bcrypt = require('bcrypt');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
|
|
|
|
|
const fastify = require("fastify");
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId } = require("../models/store");
|
|
|
|
logger: true,
|
|
|
|
|
|
|
|
//disableRequestLogging: true,
|
|
|
|
|
|
|
|
genReqId(req) {
|
|
|
|
|
|
|
|
// you get access to the req here if you need it - must be a synchronous function
|
|
|
|
|
|
|
|
return uuidv4();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});const { Install, ProfilePictureInstall, generateinstallationId } = require("../models/store");
|
|
|
|
|
|
|
|
|
|
|
|
const supplierController = require("../controllers/supplierController")
|
|
|
|
const supplierController = require("../controllers/supplierController")
|
|
|
|
|
|
|
|
|
|
|
@ -84,33 +90,80 @@ exports.installSignUp = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.installLogin = async (request, reply) => {
|
|
|
|
// exports.installLogin = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
const { phone, password } = request.body
|
|
|
|
// const { phone, password } = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
// Check if an admin with the email address exists
|
|
|
|
// // Check if an install with the phone number exists
|
|
|
|
const install = await Install.findOne({ phone })
|
|
|
|
// const install = await Install.findOne({ phone });
|
|
|
|
|
|
|
|
|
|
|
|
if (!install) {
|
|
|
|
// if (!install) {
|
|
|
|
return reply.status(401).send({ message: 'Invalid Phone or password' })
|
|
|
|
// return reply.status(401).send({
|
|
|
|
}
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: true,
|
|
|
|
// Compare the password entered by the user with the hashed password stored in the database
|
|
|
|
// message: 'Invalid Phone or password'
|
|
|
|
const isPasswordValid = await bcrypt.compare(password, install.services.password.bcrypt)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
if (!isPasswordValid) {
|
|
|
|
// }
|
|
|
|
return reply.status(401).send({ message: 'Invalid phone or password' })
|
|
|
|
|
|
|
|
}
|
|
|
|
// // Compare the password entered by the user with the hashed password stored in the database
|
|
|
|
|
|
|
|
// const isPasswordValid = await bcrypt.compare(password, install.services.password.bcrypt);
|
|
|
|
// Generate a JWT token for the authenticated admin
|
|
|
|
|
|
|
|
const token = jwt.sign({ phone: install.phone }, 'secret')
|
|
|
|
// if (!isPasswordValid) {
|
|
|
|
|
|
|
|
// return reply.status(401).send({
|
|
|
|
// Return the token and user details to the client
|
|
|
|
// simplydata: {
|
|
|
|
return { token, user: install }
|
|
|
|
// error: true,
|
|
|
|
} catch (err) {
|
|
|
|
// message: 'Invalid phone or password'
|
|
|
|
reply.status(500).send({ message: err.message })
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Generate a JWT token for the authenticated install
|
|
|
|
|
|
|
|
// const token = fastify.jwt.sign({ phone: install.phone }, 'your_jwt_secret', { expiresIn: '30d' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Fetch the profile picture if it exists
|
|
|
|
|
|
|
|
// const profilePicture = await ProfilePictureInstall.findOne({ customerId: install._id });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const responsePayload = {
|
|
|
|
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: false,
|
|
|
|
|
|
|
|
// apiversion: fastify.config.APIVERSION,
|
|
|
|
|
|
|
|
// access_token: token,
|
|
|
|
|
|
|
|
// email: install.emails,
|
|
|
|
|
|
|
|
// installationId: install.installationId,
|
|
|
|
|
|
|
|
// phone: install.phone,
|
|
|
|
|
|
|
|
// address1: install.address1,
|
|
|
|
|
|
|
|
// address2: install.address2,
|
|
|
|
|
|
|
|
// phoneVerified: install.phoneVerified,
|
|
|
|
|
|
|
|
// oneTimePasswordSetFlag: install.oneTimePasswordSetFlag,
|
|
|
|
|
|
|
|
// type: install.profile.role,
|
|
|
|
|
|
|
|
// fcmId: install.fcmId,
|
|
|
|
|
|
|
|
// team: install.team,
|
|
|
|
|
|
|
|
// city: install.city,
|
|
|
|
|
|
|
|
// manager: install.manager,
|
|
|
|
|
|
|
|
// firstName: install.firstName,
|
|
|
|
|
|
|
|
// lastName: install.lastName,
|
|
|
|
|
|
|
|
// address: install.address,
|
|
|
|
|
|
|
|
// alternativeNumber: install.alternativeNumber,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (profilePicture) {
|
|
|
|
|
|
|
|
// responsePayload.simplydata.picture = profilePicture.picture;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Return the token and user details to the client
|
|
|
|
|
|
|
|
// return reply.send(responsePayload);
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// reply.status(500).send({
|
|
|
|
|
|
|
|
// simplydata: {
|
|
|
|
|
|
|
|
// error: true,
|
|
|
|
|
|
|
|
// message: err.message
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|