deliveryboy login

master
Bhaskara Kishore 3 years ago
parent 1ec8d8b6fa
commit c78755ae4b

@ -10,7 +10,7 @@ const saltRounds = 10;
//Get the data models //Get the data models
const { Supplier ,ProfilePicture, generateSupplierId} = require('../models/supplier'); const { Supplier ,ProfilePicture, generateSupplierId, DeliveryBoy} = require('../models/supplier');
async function bcryptPassword(password) { async function bcryptPassword(password) {
@ -55,6 +55,29 @@ exports.loginSupplier = async (req) => {
//DeliveryBoy Login Controller
exports.loginDeliveryBoy = async (req) => {
try {
const phone = req.body.phone;
const delivery = await DeliveryBoy.findOne({ phone: phone });
if (delivery) {
return { same: true, delivery: delivery };
} else {
return { same: false };
}
} catch (err) {
throw boom.boomify(err);
}
};
exports.addSupplier = async (req, reply) => { exports.addSupplier = async (req, reply) => {
try { try {
// await resetCounter();//to set customer id back to 0 // await resetCounter();//to set customer id back to 0

@ -235,6 +235,114 @@ exports.loginSupplier = async(request, reply) =>{
} }
//Login Delivery Handler
exports.loginDeliveryBoy = async(request, reply) =>{
loginObject = await supplierController.loginDeliveryBoy(request);
console.log("loginObject...",loginObject)
if (loginObject.same) {
const phoneVerified = loginObject.delivery.phoneVerified;
const oneTimePasswordSetFlag = loginObject.delivery.oneTimePasswordSetFlag;
console.log(
"oneTimePasswordSetFlag is ......",
oneTimePasswordSetFlag,
typeof oneTimePasswordSetFlag,
typeof phoneVerified
);
if (!phoneVerified) {
reply.send({
simplydata: {
error: false,
phoneVerified: false,
phone: loginObject.delivery.phone,
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
message: "Please Verify your phone number",
},
});
} else if (oneTimePasswordSetFlag) {
reply.send({
simplydata: {
error: false,
phoneVerified: phoneVerified,
phone: loginObject.delivery.phone,
oneTimePasswordSetFlag: true,
message: "Password must be reset",
},
});
} else {
const token = fastify.jwt.sign(
{
deliveryBoyname: loginObject.delivery.name,
deliveryBoyId: loginObject.delivery._id,
},
//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" }
);
console.log(token, "..token")
var d_id = loginObject.delivery._id
console.log(d_id,"deliveryId")
var profilePicture = await ProfilePicture.findOne({ deliveryBoyId:d_id});
// request.session.set('supplierId', loginObject.supplier._id)
if (!profilePicture) {
reply.send({
simplydata: {
error: false,
apiversion: fastify.config.APIVERSION,
access_token: token,
phone: loginObject.delivery.phone,
deliveryBoyId: loginObject.delivery.deliveryBoyId,
deliveryBoyname: loginObject.delivery.name,
address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
},
});
}if (profilePicture) {
reply.send({
simplydata: {
error: false,
apiversion: fastify.config.APIVERSION,
access_token: token,
picture:profilePicture.picture,
phone: loginObject.delivery.phone,
deliveryBoyId: loginObject.delivery.deliveryBoyId,
deliveryBoyname: loginObject.delivery.name,
address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
},
});
}
}
} else {
error = {
simplydata: {
error: true,
code: 400,
message: "Invalid Details",
},
};
reply.send(error);
}
}
// Check if all the required fields are supplied by the user // Check if all the required fields are supplied by the user
exports.fieldCheck = async (req, reply) => { exports.fieldCheck = async (req, reply) => {

@ -111,6 +111,10 @@ const supplierSchema = new mongoose.Schema(
name: { type: String, default: null }, name: { type: String, default: null },
phone: { type: String, default: null,unique:true }, phone: { type: String, default: null,unique:true },
alternativeContactNumber : { type : String,default: null }, alternativeContactNumber : { type : String,default: null },
phoneVerified: { type: Boolean, default: false },
phoneVerificationCode: { type: Number, default: 11111 },
passwordResetCode: { type: Number, default: code },
oneTimePasswordSetFlag: { type: Boolean, default: false },
address: { type: String, default: null }, address: { type: String, default: null },
city: { type: String, default: null }, city: { type: String, default: null },
state: { type: String, default: null }, state: { type: String, default: null },

@ -101,6 +101,22 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.post("/api/deliveryboylogin", {
schema: {
description: "This is for Login Delivery Boy",
tags: ["Supplier-Data"],
summary: "This is for Login Delivery Boy",
body: {
type: "object",
required: ["phone"],
properties: {
phone: { type: "string" },
},
},
},
handler: validationHandler.loginDeliveryBoy,
});
fastify.route({ fastify.route({
method: "POST", method: "POST",
url: "/api/supplierlogout", url: "/api/supplierlogout",

Loading…
Cancel
Save