Commit a0f93740 by kashif ansari

login user OTP issue fix

1 parent 153aebb0
......@@ -30,8 +30,6 @@ const userPermissionExtension = (plugin) => {
);
}
console.log(`Will be using params: `);
console.log(emailAddress, mobileNumber);
const pluginStore = await strapi.store({
type: "plugin",
......@@ -40,15 +38,30 @@ const userPermissionExtension = (plugin) => {
const emailSettings = await pluginStore.get({ key: "email" });
// Find the channel partner first.
const endUser = await strapi.query("api::end-user.end-user").findOne({
populate: ["user"],
where: {
$and: [
{ publishedAt: { $notNull: true } },
{ mobileNo: mobileNumber },
],
},
});
// const endUser = await strapi.query("api::end-user.end-user").findOne({
// populate: ["user"],
// where: {
// $and: [
// { publishedAt: { $notNull: true } },
// { mobileNo: mobileNumber },
// ],
// },
// });
const endUser = await strapi
.query("api::end-user.end-user")
.findOne({
populate: ["user"],
where: {
$and: [
{ publishedAt: { $notNull: true } },
{ mobileNo: mobileNumber },
],
},
});
if (!endUser) {
throw new ValidationError(
"No end user registered with specified email address, mobile number combination."
......@@ -58,7 +71,7 @@ const userPermissionExtension = (plugin) => {
// Find the linked user next.
const user = await strapi
.query("plugin::users-permissions.user")
.findOne({ id: endUser.user.id });
.findOne({where:{ id: endUser.user.id }});
if (!user || user.blocked) {
throw new ValidationError("Unable to resolve user linked to end user.");
}
......@@ -69,7 +82,7 @@ const userPermissionExtension = (plugin) => {
{}
);
const oneTimePassword = Math.floor(100000 + Math.random() * 900000);
console.log("oneTimePassword",oneTimePassword);
const emailToSend = {
to: user.email,
from:
......@@ -81,12 +94,12 @@ const userPermissionExtension = (plugin) => {
text: `Hello ${endUser.fullName}, Your one time password to login to your partner portal is ${oneTimePassword}`,
html: `<p>Hello ${endUser.fullName}, <br></br>Your one time password to login to the hiranandani offers portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`,
};
console.log('user',user);
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
const updateUser=await getService("user").edit(user.id, {
oneTimePassword: `${oneTimePassword}`,
});
console.log("updateUser",updateUser);
// Send an email to the user.
await strapi.plugin("email").service("email").send(emailToSend);
......@@ -122,8 +135,7 @@ const userPermissionExtension = (plugin) => {
);
}
console.log(`Loaded end user:`);
console.log(endUser);
// Find the linked user next.
const user = await strapi.query("plugin::users-permissions.user").findOne({
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!