From 9af1854a7e35785a8e86426c4fb1edd465f164a3 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Thu, 1 Jan 2026 18:32:49 -0800 Subject: Massive refactor courtesy of 5 dollars of AI tokens --- src/routes/contact/+page.svelte | 325 +++++++++++++++++++++++++++++++++++ src/routes/contact/index.svelte | 158 ----------------- src/routes/contact/submit.js | 102 ----------- src/routes/contact/submit/+server.js | 97 +++++++++++ 4 files changed, 422 insertions(+), 260 deletions(-) create mode 100644 src/routes/contact/+page.svelte delete mode 100644 src/routes/contact/index.svelte delete mode 100644 src/routes/contact/submit.js create mode 100644 src/routes/contact/submit/+server.js (limited to 'src/routes/contact') diff --git a/src/routes/contact/+page.svelte b/src/routes/contact/+page.svelte new file mode 100644 index 0000000..c66d9df --- /dev/null +++ b/src/routes/contact/+page.svelte @@ -0,0 +1,325 @@ + + +
+
+

Contact

+
+ + {#if noticeMessage} +
+ {noticeMessage} +
+ {/if} + +
+
+
+

Details

+ + +
+ +
+

In a crisis?

+

+ We do not have a crisis line. If you or someone you know is in danger please call 911, visit your + nearest emergency room, call the National Suicide Prevention Lifeline at + (800)273-TALK (8255), or text HELLO to 741-741. +

+
+
+ +
+

Send a message

+
+
+ + + + + + + +
+ +
+ +
+ +
+ +

+ Please watch spam for replies. +

+
+
+
+
+
+ + diff --git a/src/routes/contact/index.svelte b/src/routes/contact/index.svelte deleted file mode 100644 index 5bd68f1..0000000 --- a/src/routes/contact/index.svelte +++ /dev/null @@ -1,158 +0,0 @@ - - -
-

Get in touch.

-
- -
-

-

- Scheduling and Other -
- (208) 499 - 4517 -

-
-
-

-
-

- Billing -
- billing@mistymountainstherapy.com -

-

- Inquiries -
- contact@mistymountainstherapy.com -

-
note: please watch spam for replies
-
-
-
-
-
-
-

Or send us a message.

-
-
- - -
-
- - -
-
-
- - -
-
- - -
-
- -
- -
note: please watch spam for any replies
-
-
- -
-
-
-
- We do not have a crisis line. If you or someone you know is in danger please call 911, visit - your nearest emergency room, call the National Suicide Prevention Lifeline for free crisis - counseling at (800)273-TALK (8255), or text HELLO to 741-741. -
-
-
-
-
diff --git a/src/routes/contact/submit.js b/src/routes/contact/submit.js deleted file mode 100644 index 0befd0e..0000000 --- a/src/routes/contact/submit.js +++ /dev/null @@ -1,102 +0,0 @@ -import 'dotenv/config'; -import * as nodemailer from 'nodemailer'; -import { continueRetryUntilValidation } from '$lib/utils'; - -class MistyMountainsMailer { - constructor(username, password, from, domain, port) { - this.from = from; - this.username = username; - this.password = password; - this.domain = domain; - this.port = port; - - this.transporter = nodemailer.createTransport({ - host: this.domain, - port: this.port, - auth: { - user: this.username, - pass: this.password - }, - requireTLS: true, - tls: { - rejectUnauthorized: true - } - }); - } - - async sendMail(to, subject, message) { - const mail = { - from: this.from, - subject, - html: message, - to - }; - - return !!(await continueRetryUntilValidation(async () => { - const { messageId } = await this.transporter.sendMail(mail); - return messageId; - })); - } -} - -export async function post({ request }) { - const body = await request.json(); - const { HCAPTCHA_SECRET, FORM_TO_EMAIL } = process.env; - const mailer = new MistyMountainsMailer( - process.env.SMTP_USERNAME, - process.env.SMTP_PASSWORD, - process.env.FROM_EMAIL, - process.env.SMTP_SERVER, - Number(process.env.SMTP_PORT) - ); - - const captchaVerified = await fetch( - `https://hcaptcha.com/siteverify?response=${body.captchaToken}&secret=${HCAPTCHA_SECRET}`, - { - method: 'POST' - } - ) - .then((res) => res.json()) - .then((json) => json.success) - .catch(() => false); - - if (!captchaVerified) { - return { - statusCode: 400, - body: { - error: 'Captcha verification failed' - } - }; - } - - const text = `

New MMT Message -

Name: ${body.name}

-

Phone Number: ${body.phone || 'Not Given'}

-

Email: ${body.email}

-
-
-

${body.message}

`; - - const messageSent = await mailer - .sendMail(FORM_TO_EMAIL, `[MMT-FORM]: New Message From ${body.name}`, text) - .then(() => true) - .catch((error) => { - console.error(error); - return false; - }); - - if (!messageSent) { - return { - statusCode: 500, - body: { - error: 'Message could not be sent' - } - }; - } - - return { - body: { - success: true - } - }; -} diff --git a/src/routes/contact/submit/+server.js b/src/routes/contact/submit/+server.js new file mode 100644 index 0000000..eed95fe --- /dev/null +++ b/src/routes/contact/submit/+server.js @@ -0,0 +1,97 @@ +import 'dotenv/config'; +import * as nodemailer from 'nodemailer'; +import { continueRetryUntilValidation } from '$lib/utils'; + +class MistyMountainsMailer { + constructor(username, password, from, domain, port) { + this.from = from; + this.username = username; + this.password = password; + this.domain = domain; + this.port = port; + + this.transporter = nodemailer.createTransport({ + host: this.domain, + port: this.port, + auth: { + user: this.username, + pass: this.password + }, + requireTLS: true, + tls: { + rejectUnauthorized: true + } + }); + } + + async sendMail(to, subject, message) { + const mail = { + from: this.from, + subject, + html: message, + to + }; + + return !!(await continueRetryUntilValidation(async () => { + const { messageId } = await this.transporter.sendMail(mail); + return messageId; + })); + } +} + +export async function POST({ request }) { + const body = await request.json(); + const { HCAPTCHA_SECRET, FORM_TO_EMAIL } = process.env; + const mailer = new MistyMountainsMailer( + process.env.SMTP_USERNAME, + process.env.SMTP_PASSWORD, + process.env.FROM_EMAIL, + process.env.SMTP_SERVER, + Number(process.env.SMTP_PORT) + ); + + const captchaVerified = await fetch( + `https://hcaptcha.com/siteverify?response=${body.captchaToken}&secret=${HCAPTCHA_SECRET}`, + { + method: 'POST' + } + ) + .then((res) => res.json()) + .then((json) => json.success) + .catch(() => false); + + if (!captchaVerified) { + return new Response(JSON.stringify({ error: 'Captcha verification failed' }), { + status: 400, + headers: { 'Content-Type': 'application/json' } + }); + } + + const text = `

New MMT Message +

Name: ${body.name}

+

Phone Number: ${body.phone || 'Not Given'}

+

Email: ${body.email}

+
+
+

${body.message}

`; + + const messageSent = await mailer + .sendMail(FORM_TO_EMAIL, `[MMT-FORM]: New Message From ${body.name}`, text) + .then(() => true) + .catch((error) => { + console.error(error); + return false; + }); + + if (!messageSent) { + return new Response(JSON.stringify({ error: 'Message could not be sent' }), { + status: 500, + headers: { 'Content-Type': 'application/json' } + }); + } + + return new Response(JSON.stringify({ success: true }), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }); +} -- cgit v1.2.3-70-g09d2