Commit a0f93740 by kashif ansari

login user OTP issue fix

1 parent 153aebb0
...@@ -30,8 +30,6 @@ const userPermissionExtension = (plugin) => { ...@@ -30,8 +30,6 @@ const userPermissionExtension = (plugin) => {
); );
} }
console.log(`Will be using params: `);
console.log(emailAddress, mobileNumber);
const pluginStore = await strapi.store({ const pluginStore = await strapi.store({
type: "plugin", type: "plugin",
...@@ -40,15 +38,30 @@ const userPermissionExtension = (plugin) => { ...@@ -40,15 +38,30 @@ const userPermissionExtension = (plugin) => {
const emailSettings = await pluginStore.get({ key: "email" }); const emailSettings = await pluginStore.get({ key: "email" });
// Find the channel partner first. // Find the channel partner first.
const endUser = await strapi.query("api::end-user.end-user").findOne({ // const endUser = await strapi.query("api::end-user.end-user").findOne({
populate: ["user"], // populate: ["user"],
where: { // where: {
$and: [ // $and: [
{ publishedAt: { $notNull: true } }, // { publishedAt: { $notNull: true } },
{ mobileNo: mobileNumber }, // { mobileNo: mobileNumber },
], // ],
}, // },
}); // });
const endUser = await strapi
.query("api::end-user.end-user")
.findOne({
populate: ["user"],
where: {
$and: [
{ publishedAt: { $notNull: true } },
{ mobileNo: mobileNumber },
],
},
});
if (!endUser) { if (!endUser) {
throw new ValidationError( throw new ValidationError(
"No end user registered with specified email address, mobile number combination." "No end user registered with specified email address, mobile number combination."
...@@ -58,7 +71,7 @@ const userPermissionExtension = (plugin) => { ...@@ -58,7 +71,7 @@ const userPermissionExtension = (plugin) => {
// Find the linked user next. // Find the linked user next.
const user = await strapi const user = await strapi
.query("plugin::users-permissions.user") .query("plugin::users-permissions.user")
.findOne({ id: endUser.user.id }); .findOne({where:{ id: endUser.user.id }});
if (!user || user.blocked) { if (!user || user.blocked) {
throw new ValidationError("Unable to resolve user linked to end user."); throw new ValidationError("Unable to resolve user linked to end user.");
} }
...@@ -69,7 +82,7 @@ const userPermissionExtension = (plugin) => { ...@@ -69,7 +82,7 @@ const userPermissionExtension = (plugin) => {
{} {}
); );
const oneTimePassword = Math.floor(100000 + Math.random() * 900000); const oneTimePassword = Math.floor(100000 + Math.random() * 900000);
console.log("oneTimePassword",oneTimePassword);
const emailToSend = { const emailToSend = {
to: user.email, to: user.email,
from: from:
...@@ -81,12 +94,12 @@ const userPermissionExtension = (plugin) => { ...@@ -81,12 +94,12 @@ const userPermissionExtension = (plugin) => {
text: `Hello ${endUser.fullName}, Your one time password to login to your partner portal is ${oneTimePassword}`, 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.`, 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 // 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, { const updateUser=await getService("user").edit(user.id, {
oneTimePassword: `${oneTimePassword}`, oneTimePassword: `${oneTimePassword}`,
}); });
console.log("updateUser",updateUser);
// Send an email to the user. // Send an email to the user.
await strapi.plugin("email").service("email").send(emailToSend); await strapi.plugin("email").service("email").send(emailToSend);
...@@ -122,8 +135,7 @@ const userPermissionExtension = (plugin) => { ...@@ -122,8 +135,7 @@ const userPermissionExtension = (plugin) => {
); );
} }
console.log(`Loaded end user:`);
console.log(endUser);
// Find the linked user next. // Find the linked user next.
const user = await strapi.query("plugin::users-permissions.user").findOne({ 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!