varun 2 years ago
commit f38990e6ab

@ -18,6 +18,7 @@ var twilioAuthToken = "7710db3aea89b94027155e6ae774b688"; // Your Auth Token fro
const libphonenumberjs = require("libphonenumber-js");
const emailValidator = require("email-validator");
const { Supplier } = require('../models/supplier');
//function to encrypt password.
//used bcrypt module.
@ -588,27 +589,27 @@ exports.resetPassword = async (req, reply) => {
user = checkFormEncoding.user;
}
phone = user.phone;
resetPasswordCode = user.resetPasswordCode;
phoneVerificationCode = user.phoneVerificationCode;
newPassword = user.newPassword;
hash = await bcryptPassword(newPassword);
console.log(user);
console.log("user===", user);
// check if user exists in the system. If user exists , display message that
// username is not available
userExists = await User.findOne({
phone: phone,
passwordResetCode: resetPasswordCode,
// phoneVerificationCode: phoneVerificationCode,
});
console.log(userExists);
console.log("userExists===", userExists);
if (userExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
passwordResetCode: resetPasswordCode,
//phoneVerificationCode: phoneVerificationCode,
};
console.log(filter);
console.log("filter", filter);
const update = {
$set: {
@ -649,6 +650,77 @@ exports.resetPassword = async (req, reply) => {
}
};
exports.resetPasswordSupplier = async (req, reply) => {
try {
console.log(" in reset Password method");
var user = req.body;
// Handle if the user data is supplied via a url encoded form
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
user = checkFormEncoding.user;
}
phone = user.phone;
phoneVerificationCode = user.phoneVerificationCode;
newPassword = user.newPassword;
hash = await bcryptPassword(newPassword);
console.log("user===", user);
// check if user exists in the system. If user exists , display message that
// username is not available
userExists = await Supplier.findOne({
phone: phone,
// phoneVerificationCode: phoneVerificationCode,
});
console.log("userExists===", userExists);
if (userExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
//phoneVerificationCode: phoneVerificationCode,
};
console.log("filter", filter);
const update = {
$set: {
"services.password.bcrypt": hash,
oneTimePasswordSetFlag: false,
},
};
console.log(update);
const doc = await Supplier.updateOne(filter, update);
// updatedUser = await User.findOne({ phone: phone });
if (doc) {
reply.send('{"armintatankdata":{"error":false,"passwordReset": true}}');
} else {
error = {
armintatankdata: {
error: true,
code: 10007,
message: "10007 - Password Reset code entered cannot be validated.",
},
};
req.body.regError = error;
reply.send(error);
}
} else {
error = {
armintatankdata: {
error: true,
code: 10008,
message: "10008 - Either Phone or Temporary Code is Invalid.",
},
};
req.body.regError = error;
reply.send(error);
}
} catch (err) {
throw boom.boomify(err);
}
};
exports.resetPasswordFromAdmin = async (req, reply) => {
try {
var { userId } = req.body;

@ -284,6 +284,34 @@ module.exports = function (fastify, opts, next) {
// onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)}
});
fastify.route({
method: "POST",
url: "/api/resetpasswordsupplier",
schema: {
tags: ["Supplier"],
description: "This is for Supplier Reset Password.",
summary: "This is for Supplier Reset Password.",
body: {
type: "object",
required: ["phone", "resetPasswordCode", "newPassword"],
properties: {
phone: { type: "string" },
resetPasswordCode: { type: "string" },
newPassword: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
//preHandler: [validationHandler],
handler: validationHandler.resetPasswordSupplier,
// onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)}
});
fastify.route({
method: "POST",
url: "/api/resetPasswordFromAdmin",

Loading…
Cancel
Save