From fd79bb7659bb213ac39166be289873de6832a765 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Sun, 6 Oct 2024 22:28:46 -0700 Subject: [PATCH] Hostname bot filter --- src/app/(main)/contact-us/page.jsx | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/app/(main)/contact-us/page.jsx b/src/app/(main)/contact-us/page.jsx index 964c7fd..2d7063e 100644 --- a/src/app/(main)/contact-us/page.jsx +++ b/src/app/(main)/contact-us/page.jsx @@ -9,13 +9,18 @@ import { Container } from '@/components/Container' export default async function Page({ searchParams }) { const firstName = searchParams['first-name']; const lastName = searchParams['last-name']; + const hostName = searchParams['host-name']; const email = searchParams['email']; const message = searchParams['message']; - const submitted = firstName || lastName || email || message; - const valid = submitted && firstName && lastName && email && message; + const submitted = firstName || lastName || email || message || hostName; + const valid = submitted && firstName && lastName && email && message && hostName; + const validHostName = valid && + (hostName.toLowerCase().replaceAll(' ', '') === 'thomashintz' || + hostName.toLowerCase().replaceAll(' ', '') === 'thomas' || + hostName.toLowerCase().replaceAll(' ', '') === 'hintz'); let emailSentSuccessfully = false; - if (valid) { + if (valid && validHostName) { const transporter = nodemailer.createTransport({ host: process.env.CONTACT_HOST, port: 587, @@ -39,6 +44,8 @@ export default async function Page({ searchParams }) { }), }); redirect('/contact-success') + } else if (!validHostName) { + redirect('/contact-success') } return ( @@ -47,7 +54,7 @@ export default async function Page({ searchParams }) {

Contact Us

- {valid && !emailSentSuccessfully && ( + {valid && validHostName && !emailSentSuccessfully && (

Unable to send message. Please go back and reload the page and try again or try again later. Sorry! @@ -117,6 +124,23 @@ export default async function Page({ searchParams }) {

+
+ +
+ +
+
+