From 7d5518865acd13458e64e0d8b3a7b4068fa56d2c Mon Sep 17 00:00:00 2001 From: pulipakaa24 Date: Thu, 8 Jan 2026 15:18:15 -0600 Subject: [PATCH] use user-sent time for email coloring --- index.js | 4 ++-- mailer.js | 39 +++++++++++++-------------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 21c97f1..c9f77e0 100644 --- a/index.js +++ b/index.js @@ -833,7 +833,7 @@ app.post('/forgot-password', async (req, res) => { }); } - const { email } = req.body; + const { email, localHour } = req.body; if (!email) { return res.status(400).json({ error: 'Email is required' }); @@ -868,7 +868,7 @@ app.post('/forgot-password', async (req, res) => { await agenda.schedule(expiresAt, 'deletePasswordResetToken', { email }); // Send email - await sendPasswordResetEmail(email, code, user.name); + await sendPasswordResetEmail(email, code, user.name, localHour); res.status(200).json({ message: 'If an account exists, a reset code has been sent' }); } catch (err) { diff --git a/mailer.js b/mailer.js index 3aa4da5..51bf6d4 100644 --- a/mailer.js +++ b/mailer.js @@ -15,36 +15,23 @@ const transporter = nodemailer.createTransport({ }); // Helper function to get color based on time of day -function getColorForTime() { - const hour = new Date().getHours(); - +// hour parameter should be the local hour (0-23) from the client +function getColorForTime(hour) { if (hour >= 5 && hour < 10) { // Morning - orange - return { - primary: '#FF9800', - gradient: 'linear-gradient(135deg, #FF9800 0%, #F57C00 100%)', - shadow: 'rgba(255, 152, 0, 0.3)' - }; + return '#FF9800'; } else if (hour >= 10 && hour < 18) { // Afternoon - blue - return { - primary: '#2196F3', - gradient: 'linear-gradient(135deg, #2196F3 0%, #005CA8 100%)', - shadow: 'rgba(33, 150, 243, 0.3)' - }; + return '#2196F3'; } else { // Evening/Night - purple - return { - primary: '#471189', - gradient: 'linear-gradient(135deg, #BA82FF 0%, #280059 100%)', - shadow: 'rgba(71, 17, 137, 0.3)' - }; + return '#471189'; } } // Helper function to send email -async function sendVerificationEmail(toEmail, token, name) { - const colors = getColorForTime(); +async function sendVerificationEmail(toEmail, token, name, localHour = new Date().getHours()) { + const primaryColor = getColorForTime(localHour); const verificationLink = `https://wahwa.com/verify-email?token=${token}`; try { @@ -78,7 +65,7 @@ async function sendVerificationEmail(toEmail, token, name) {

- Welcome${name && name.trim() ? `, ${name.trim()}` : ''}! + Welcome${name && name.trim() ? `, ${name.trim()}` : ''}!

Thank you for joining BlindMaster! To electrify your blinds, please verify your email address 🥹 @@ -90,7 +77,7 @@ async function sendVerificationEmail(toEmail, token, name) { + style="display: inline-block; padding: 16px 48px; background-color: ${primaryColor}; color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: bold; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); transition: all 0.3s ease;"> Verify Email Address @@ -141,8 +128,8 @@ async function sendVerificationEmail(toEmail, token, name) { } // Helper function to send password reset email -async function sendPasswordResetEmail(toEmail, code, name) { - const colors = getColorForTime(); +async function sendPasswordResetEmail(toEmail, code, name, localHour = new Date().getHours()) { + const primaryColor = getColorForTime(localHour); try { const info = await transporter.sendMail({ @@ -186,8 +173,8 @@ async function sendPasswordResetEmail(toEmail, code, name) { -

-

+

+

${code}