Commit 38ef085d by jaymehta

.

1 parent 51407922
...@@ -58,6 +58,15 @@ module.exports = createCoreController("api::end-user.end-user", () => ({ ...@@ -58,6 +58,15 @@ module.exports = createCoreController("api::end-user.end-user", () => ({
}, },
} }
); );
const sendEmailres = await strapi
.service("api::vendor.vendor")
.sendMail({
email: ctx.request.body.data.email,
oneTimePassword: oneTimePassword,
name: ctx.request.body.data.email,
});
console.log("sendEmailres", sendEmailres);
const date = new Date(); const date = new Date();
// TODO: Code to send OTP on email // TODO: Code to send OTP on email
// TODO: Code to send OTP on SMS // TODO: Code to send OTP on SMS
......
...@@ -73,6 +73,13 @@ module.exports = createCoreController("api::vendor.vendor", () => ({ ...@@ -73,6 +73,13 @@ module.exports = createCoreController("api::vendor.vendor", () => ({
}, },
} }
); );
const sendEmailres = await strapi.service("api::vendor.vendor").sendMail({
email: ctx.request.body.data.email,
oneTimePassword: oneTimePassword,
name: ctx.request.body.data.email,
});
console.log("sendEmailres", sendEmailres);
const date = new Date(); const date = new Date();
// TODO: Code to send OTP on email // TODO: Code to send OTP on email
// TODO: Code to send OTP on SMS // TODO: Code to send OTP on SMS
...@@ -84,25 +91,32 @@ module.exports = createCoreController("api::vendor.vendor", () => ({ ...@@ -84,25 +91,32 @@ module.exports = createCoreController("api::vendor.vendor", () => ({
} else { } else {
console.log("but is here"); console.log("but is here");
let final; let final;
let str = ctx.request.body.data.name let str = ctx.request.body.data.name;
// console.log() // console.log()
let newStr = str.replace(/ /g,'').toUpperCase().replace(/[^a-zA-Z ]/g, "") let newStr = str
.replace(/ /g, "")
.toUpperCase()
.replace(/[^a-zA-Z ]/g, "");
if (newStr.length >= 4) { if (newStr.length >= 4) {
final = newStr.slice(0, 4)+String(Math.floor(Math.random() * 90000) + 10000); final =
// console.log(final+String(Math.floor(Math.random() * 90000) + 10000)) newStr.slice(0, 4) +
} else {1 String(Math.floor(Math.random() * 90000) + 10000);
final = newStr.slice(0, 4)+String(Math.floor(Math.random() * 90000) + 10000) // console.log(final+String(Math.floor(Math.random() * 90000) + 10000))
// console.log(final+String(Math.floor(Math.random() * 90000) + 10000)) } else {
1;
final =
newStr.slice(0, 4) +
String(Math.floor(Math.random() * 90000) + 10000);
// console.log(final+String(Math.floor(Math.random() * 90000) + 10000))
} }
ctx.request.body.data.user = currentUser.id; ctx.request.body.data.user = currentUser.id;
const response = await strapi.entityService.create("api::vendor.vendor", { const response = await strapi.entityService.create("api::vendor.vendor", {
data: { data: {
...ctx.request.body.data, ...ctx.request.body.data,
phone: ctx.request.body.data.mobileNo, phone: ctx.request.body.data.mobileNo,
publishedAt: date, publishedAt: date,
uniqueVendorId: final uniqueVendorId: final,
}, },
}); });
console.log("response", response); console.log("response", response);
...@@ -190,19 +204,19 @@ module.exports = createCoreController("api::vendor.vendor", () => ({ ...@@ -190,19 +204,19 @@ module.exports = createCoreController("api::vendor.vendor", () => ({
name: "Zango", name: "Zango",
link: "https://mailgen.js/", link: "https://mailgen.js/",
// Optional product logo // Optional product logo
logo: 'https://zangoaws.s3.amazonaws.com/main_logo_e32eeef63e.svg?updated_at=2024-06-26T11:05:28.634Z' logo: "https://zangoaws.s3.amazonaws.com/main_logo_e32eeef63e.svg?updated_at=2024-06-26T11:05:28.634Z",
}, },
}); });
var email = { var email = {
body: { body: {
name: "Jay Mehta", name: ctx.request.body.name,
intro: "Welcome to Zango! We're very excited to have you on board.", intro: "Welcome to Zango! We're very excited to have you on board.",
action: { action: {
instructions: "To get started with signup, please confirm the OTP:", instructions: "To get started with signup, please confirm the OTP:",
button: { button: {
color: "red", // Optional action button color color: "red", // Optional action button color
text: "8291", text: ctx.request.body.oneTimePassword,
// link: "https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010", // link: "https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010",
}, },
}, },
...@@ -239,16 +253,13 @@ module.exports = createCoreController("api::vendor.vendor", () => ({ ...@@ -239,16 +253,13 @@ module.exports = createCoreController("api::vendor.vendor", () => ({
} }
main().catch(console.error); main().catch(console.error);
ctx.send({ok: true, message: "Email sent"}) ctx.send({ ok: true, message: "Email sent" });
}, },
async addVendorId(ctx) { async addVendorId(ctx) {
try { try {
// console.log(ctx.request.body) // console.log(ctx.request.body)
} catch (error) {}
} catch (error) {
}
}, },
async removedirectory(ctx) { async removedirectory(ctx) {
......
...@@ -262,42 +262,67 @@ module.exports = createCoreService( ...@@ -262,42 +262,67 @@ module.exports = createCoreService(
} }
}; };
}, },
async sendMail() { async sendMail(data) {
// Configure mailgen by setting a theme and your product info // Configure mailgen by setting a theme and your product info
var mailGenerator = new Mailgen({ var mailGenerator = new Mailgen({
theme: "default", theme: "default",
product: { product: {
// Appears in header & footer of e-mails // Appears in header & footer of e-mails
name: "Mailgen", name: "Zango",
link: "https://mailgen.js/", link: "https://mailgen.js/",
// Optional product logo // Optional product logo
// logo: 'https://mailgen.js/img/logo.png' logo: "https://zangoaws.s3.amazonaws.com/main_logo_e32eeef63e.svg?updated_at=2024-06-26T11:05:28.634Z",
}, },
}); });
var email = { var email = {
body: { body: {
name: "John Appleseed", name: data.name,
intro: "Welcome to Mailgen! We're very excited to have you on board.", intro: "Welcome to Zango! We're very excited to have you on board.",
action: { action: {
instructions: "To get started with Mailgen, please click here:", instructions: "To get started with signup, please confirm the OTP:",
button: { button: {
color: "#22BC66", // Optional action button color color: "red", // Optional action button color
text: "Confirm your account", text: data.oneTimePassword,
link: "https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010", // link: "https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010",
}, },
}, },
outro: outro:
"Need help, or have questions? Just reply to this email, we'd love to help.", "Need help, or have questions? Please mail on graheja@zangoexperiences.com.",
}, },
}; };
// Generate an HTML email with the provided contents // Generate an HTML email with the provided contents
var emailBody = mailGenerator.generate(email); var emailBody = mailGenerator.generate(email);
console.log("email", emailBody); // console.log("email", emailBody);
// Generate the plaintext version of the e-mail (for clients that do not support HTML)
var emailText = mailGenerator.generatePlaintext(email); var transport = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});
async function main() {
// send mail with defined transport object
const info = await transport.sendMail({
from: `<no-reply@zangoexperiences.com>`, // sender address
to: data.email, // list of receivers
subject: "OTP Verification", // Subject line
// text: "Hello world?", // plain text body
html: emailBody, // html body
});
console.log("Message sent: %s", info.messageId);
// Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
}
main().catch(console.error);
// ctx.send({ ok: true, message: "Email sent" });
return { ok: true, message: "Email sent" };
}, },
}) })
); );
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!