diff --git a/components/SignupForm.tsx b/components/SignupForm.tsx index c78059359ee6153a8cff771700d241bf912ba30b..baae491f1dc4a2f1a82a8c4d6a726647c8a68e5c 100644 --- a/components/SignupForm.tsx +++ b/components/SignupForm.tsx @@ -48,7 +48,7 @@ export default function SignupForm() { } if (status === Status.Sending || status === Status.Sent || status === Status.SentVerified) { - if (status === Status.Sending) return <div className={styles.form}><h4>Loading...</h4></div>; + if (status === Status.Sending) return <div className={styles.form}><h4>Loading... This might take a second.</h4></div>; else return ( <div className={styles.form}> <h1>Thanks! We'll keep you up to date.</h1> diff --git a/email/verify.html b/email/verify.html index ccd7cc3f21ff0fce142eb6cec82f70f3f60c9ddb..8cb49fa5afdbb93fa4e02e96a1197ac6d39aed92 100644 --- a/email/verify.html +++ b/email/verify.html @@ -3,96 +3,15 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>REVOLT - Verify your email.</title> - <style> - body { - font-family: "Open Sans", Helvetica, sans-serif; - } - - a { - color: #178AFE; - text-decoration: none; - } - - a:hover { text-decoration: underline; } - a:active { color: #1465B7; } - - span { - margin: 5px 0; - } - - hr { - border: 1px solid #C4C4C4; - } - - #bodyHeader { margin-top: 1em; } - #emailContainer { box-shadow: 0 1px 5px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); } - - #emailBody { font-weight: 600; padding: 0 10px; } - #emailBody .bodyHeader { font-weight: 700; } - #emailBody { color: #535353; } - - #emailBody .button { - background-color: #FF4654; - color: #FFFFFF; - padding: 16px 50px; - border-radius: 5px; - user-select: none; - text-decoration: none; - font-weight: 800; - } - #emailBody .button:hover { background-color: #D4313E;} - #emailBody .button:active { background-color: #AB2933;} - - #emailFooter { font-weight: 600; font-size: 14px; } - #emailFooter #noreply { color: #929292; } - </style> </head> <body> - <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable"> - <tr> - <td align="center" valign="top"> - <table border="0" cellpadding="0" cellspacing="0" width="600" id="emailContainer"> - <tr> - <td align="center" valign="top"> - <table border="0" cellpadding="0" cellspacing="0" width="100%" id="emailHeader"> - <tr> - <td align="center" valign="top"> - <img src="https://revolt.chat/header.png" width="100%" alt="REVOLT brand logo"> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <td align="center" valign="top"> - <table border="0" cellpadding="10" cellspacing="0" width="100%" id="emailBody"> - <tr> - <td valign="top"> - <h2 class="bodyHeader">Thanks for signing up!</h2> - <p>We just need to verify your email and you'll be good to go.</p> - <br><br> - <center><a class="button" href="https://revolt.chat/api/verify?id={{id}}">Verify email</a></center> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <td align="center" valign="top"> - <table border="0" cellpadding="10" cellspacing="0" width="100%" id="emailFooter"> - <tr> - <td align="center" valign="top"> - <hr> - <p><a href="https://revolt.chat/api/remove?id={{id}}">Remove me from the mailing list.</a></p> - <p id="noreply">Sent by Revolt • Do not reply to this email.</p> - </td> - </tr> - </table> - </td> - </tr> - </table> - </td> - </tr> - </table> + Thanks for signing up!<br /> + We just need to verify your email and you'll be good to go.<br /> + <br /> + <a class="button" href="https://revolt.chat/api/verify?id={{id}}">Verify email</a><br /> + <br /> + <p id="noreply">Sent by Revolt • Do not reply to this email.</p><br /> + <br /> + <p>Sorry for the lack of design here, we are having issues with spam filters! :(</p> </body> </head> \ No newline at end of file diff --git a/package.json b/package.json index 809cf22a2356a949e7c92597b68aa416c99a226f..b8987fcbf6a10c503291e34eee972ca1fc07f29c 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "mongodb": "^3.5.9", "next": "9.4.4", "next-connect": "^0.8.1", + "nodemailer": "^6.4.10", "react": "16.13.1", "react-dom": "16.13.1", "sass": "^1.26.9", diff --git a/pages/api/send.ts b/pages/api/send.ts index 359a20f3792b7b887479eafa75830dc78f604b60..d143cb6e252f64f04d8dfbf2cdbcdf1fdc7a8f9d 100644 --- a/pages/api/send.ts +++ b/pages/api/send.ts @@ -5,6 +5,7 @@ import axios from 'axios'; import { ulid } from 'ulid'; import shortid from 'shortid'; import { readFileSync } from 'fs'; +import nodemailer from 'nodemailer'; import databaseMiddleware from '../../components/middleware/database'; @@ -15,6 +16,19 @@ handler.use(databaseMiddleware); const verificationEmail = readFileSync('email/verify.html').toString(); +let transporter = nodemailer.createTransport({ + host: "mail.fatalerrorcoded.eu", + port: 587, + secure: false, + auth: { + user: process.env.SMTP_USERNAME, + pass: process.env.SMTP_PASSWORD + }, + tls: { + rejectUnauthorized: false + } +}); + handler.post(async (req: NextApiRequest, res: NextApiResponse) => { try { if (req.body.email === undefined) { @@ -42,13 +56,6 @@ handler.post(async (req: NextApiRequest, res: NextApiResponse) => { let _id = ulid(); let referral = shortid.generate(); let source_ip = req.headers['cf-connecting-ip'] ?? req.headers['x-forwarded-for'] ?? req.socket.remoteAddress; - await coll.insertOne({ - _id, - email, referral, - verified: false, - referrer_id: referrer !== null ? referrer._id : null, - source_ip - }); let fields = []; if (referrer !== null) { @@ -76,14 +83,23 @@ handler.post(async (req: NextApiRequest, res: NextApiResponse) => { ] }).then(() => {}).catch((err) => console.warn(err)); - axios.post(process.env.PORTAL_URL, { - target: email, - subject: 'REVOLT - Verify your email.', - body: `Verify your email at https://revolt.chat/api/verify?id=${_id}`, - html: verificationEmail.replace(/{{id}}/g, _id).replace(/{{ref}}/g, referral) - }).then(() => {}).catch((err) => console.warn(err)); + await transporter.sendMail({ + from: '"REVOLT" <noreply@revolt.chat>', + to: email, + subject: "Verify your email.", + text: `Thanks for signing up!\nWe just need to verify your email and you'll be good to go.\nhttps://revolt.chat/api/verify?id=${_id}\n\nSent by Revolt • Do not reply to this email.`, + html: verificationEmail.replace(/{{id}}/g, _id), + }); + + await coll.insertOne({ + _id, + email, referral, + verified: false, + referrer_id: referrer !== null ? referrer._id : null, + source_ip + }); - res.status(200).json({ success: true, referral: referral, verified: true }); + res.status(200).json({ success: true, referral: referral, verified: false }); } } catch (err) { console.error(err); diff --git a/pages/api/verify.ts b/pages/api/verify.ts index fab48bea814fccaad349cfd01a70826bc3699ab6..b7238d45cad14562ecf8471c23b546bd8777296a 100644 --- a/pages/api/verify.ts +++ b/pages/api/verify.ts @@ -21,7 +21,7 @@ handler.get(async (req: NextApiRequest, res: NextApiResponse) => { if (result) { if (result.verified) { - res.writeHead(303, { Location: '/' }); + res.writeHead(303, { Location: '/' }).end(); return; } @@ -45,7 +45,7 @@ handler.get(async (req: NextApiRequest, res: NextApiResponse) => { ] }).then(() => {}).catch((err) => console.warn(err)); - res.writeHead(303, { Location: '/' }); + res.writeHead(303, { Location: '/' }).end(); } else { res.send('Unknown ID. :('); } diff --git a/yarn.lock b/yarn.lock index c9cb5693946776b2014b9cfcdad3b1bc29766d33..edcab3a3a9c6093e9dba3bed41bc4ff7d9163a90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3829,6 +3829,11 @@ node-releases@^1.1.53, node-releases@^1.1.58: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.58.tgz#8ee20eef30fa60e52755fcc0942def5a734fe935" integrity sha512-NxBudgVKiRh/2aPWMgPR7bPTX0VPmGx5QBwCtdHitnqFE5/O8DeBXuIMH1nwNnw/aMo6AjOrpsHzfY3UbUJ7yg== +nodemailer@^6.4.10: + version "6.4.10" + resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.4.10.tgz#f4c8dc7991c57f41fd081bef224ef01f7065143d" + integrity sha512-j+pS9CURhPgk6r0ENr7dji+As2xZiHSvZeVnzKniLOw1eRAyM/7flP0u65tCnsapV8JFu+t0l/5VeHsCZEeh9g== + normalize-html-whitespace@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/normalize-html-whitespace/-/normalize-html-whitespace-1.0.0.tgz#5e3c8e192f1b06c3b9eee4b7e7f28854c7601e34"