-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import jwt from "jsonwebtoken"; | ||
import nodemailer from "nodemailer"; | ||
import client from "@/util/data/Mongo"; | ||
import { redirect } from "next/navigation"; | ||
|
||
|
@@ -90,52 +89,8 @@ export async function POST(req: NextRequest) { | |
}); */ | ||
|
||
// Initialize nodemailer | ||
const transporter = await nodemailer.createTransport({ | ||
host: "smtp.gmail.com", | ||
port: 465, | ||
secure: true, | ||
auth: { | ||
user: process.env.GMAIL_USER, | ||
pass: process.env.GMAIL_PASS, | ||
}, | ||
}); | ||
|
||
// verify connection configuration | ||
await new Promise((resolve, reject) => { | ||
transporter.verify(function (err, success) { | ||
if (err) { | ||
reject(err); | ||
return new NextResponse(JSON.stringify(err)); | ||
} else { | ||
resolve(success); | ||
} | ||
}); | ||
}); | ||
|
||
// Function to generate emailOptions | ||
const emailOptions = (url: string, to: string, teacher: boolean) => { | ||
return { | ||
from: "Exun Clan <[email protected]>", | ||
to: to, | ||
subject: `Exun 2023 ${teacher ? "Teacher In-charge " : ""}Verification`, | ||
html: ` | ||
<p> | ||
Please click on the following link to verify your email for Exun 2023. <br><br> | ||
<a href="${url}"> | ||
${url} | ||
</a> | ||
<br><br> | ||
This is your unique discord ${process.env | ||
.DISCORD_INVITE_LINK!} verification token: <b>${randomToken}</b> | ||
<br> | ||
Kindly share it with the participants of your school. | ||
<br><br> | ||
Regards, <br> | ||
Exun Clan | ||
</p> | ||
`, | ||
}; | ||
}; | ||
|
||
// Sign jwt token if email exists | ||
if (email) { | ||
|
@@ -151,20 +106,22 @@ export async function POST(req: NextRequest) { | |
); | ||
|
||
const url = `${process.env.NEXT_PUBLIC_URL}/api/user/verify?token=${token}`; | ||
|
||
await new Promise((resolve, reject) => { | ||
transporter.sendMail(emailOptions(url, email, false), (err, info) => { | ||
if (err) { | ||
reject(err); | ||
return new NextResponse(JSON.stringify(err)); | ||
} | ||
|
||
resolve(info); | ||
|
||
/* // For test account | ||
console.log(nodemailer.getTestMessageUrl(_)); */ | ||
}); | ||
}); | ||
await fetch(`https://exun-mailer.vercel.app/email?password=${"Tejas%20yaha%20password%20nhi%20milega%20tujhe%20iska%20sorry"}&to=${encodeURIComponent(email)}&subject=${encodeURIComponent(`Exun 2023 ${false ? "Teacher In-charge " : ""}Verification`)}&html=${` | ||
<p> | ||
Please click on the following link to verify your email for Exun 2023. <br><br> | ||
<a href="${url}"> | ||
${url} | ||
</a> | ||
<br><br> | ||
This is your unique discord ${process.env | ||
.DISCORD_INVITE_LINK!} verification token: <b>${randomToken}</b> | ||
<br> | ||
Kindly share it with the participants of your school. | ||
<br><br> | ||
Regards, <br> | ||
Exun Clan | ||
</p> | ||
`}`) | ||
} | ||
|
||
// Sign jwt token if teacherEmail exists | ||
|