use user-sent time for email coloring
This commit is contained in:
4
index.js
4
index.js
@@ -833,7 +833,7 @@ app.post('/forgot-password', async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { email } = req.body;
|
const { email, localHour } = req.body;
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
return res.status(400).json({ error: 'Email is required' });
|
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 });
|
await agenda.schedule(expiresAt, 'deletePasswordResetToken', { email });
|
||||||
|
|
||||||
// Send 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' });
|
res.status(200).json({ message: 'If an account exists, a reset code has been sent' });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
39
mailer.js
39
mailer.js
@@ -15,36 +15,23 @@ const transporter = nodemailer.createTransport({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Helper function to get color based on time of day
|
// Helper function to get color based on time of day
|
||||||
function getColorForTime() {
|
// hour parameter should be the local hour (0-23) from the client
|
||||||
const hour = new Date().getHours();
|
function getColorForTime(hour) {
|
||||||
|
|
||||||
if (hour >= 5 && hour < 10) {
|
if (hour >= 5 && hour < 10) {
|
||||||
// Morning - orange
|
// Morning - orange
|
||||||
return {
|
return '#FF9800';
|
||||||
primary: '#FF9800',
|
|
||||||
gradient: 'linear-gradient(135deg, #FF9800 0%, #F57C00 100%)',
|
|
||||||
shadow: 'rgba(255, 152, 0, 0.3)'
|
|
||||||
};
|
|
||||||
} else if (hour >= 10 && hour < 18) {
|
} else if (hour >= 10 && hour < 18) {
|
||||||
// Afternoon - blue
|
// Afternoon - blue
|
||||||
return {
|
return '#2196F3';
|
||||||
primary: '#2196F3',
|
|
||||||
gradient: 'linear-gradient(135deg, #2196F3 0%, #005CA8 100%)',
|
|
||||||
shadow: 'rgba(33, 150, 243, 0.3)'
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
// Evening/Night - purple
|
// Evening/Night - purple
|
||||||
return {
|
return '#471189';
|
||||||
primary: '#471189',
|
|
||||||
gradient: 'linear-gradient(135deg, #BA82FF 0%, #280059 100%)',
|
|
||||||
shadow: 'rgba(71, 17, 137, 0.3)'
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to send email
|
// Helper function to send email
|
||||||
async function sendVerificationEmail(toEmail, token, name) {
|
async function sendVerificationEmail(toEmail, token, name, localHour = new Date().getHours()) {
|
||||||
const colors = getColorForTime();
|
const primaryColor = getColorForTime(localHour);
|
||||||
const verificationLink = `https://wahwa.com/verify-email?token=${token}`;
|
const verificationLink = `https://wahwa.com/verify-email?token=${token}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +65,7 @@ async function sendVerificationEmail(toEmail, token, name) {
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="padding: 50px 40px 30px 40px; text-align: center;">
|
<td style="padding: 50px 40px 30px 40px; text-align: center;">
|
||||||
<h2 style="margin: 0 0 20px 0; color: #333333; font-size: 28px; font-weight: normal;">
|
<h2 style="margin: 0 0 20px 0; color: #333333; font-size: 28px; font-weight: normal;">
|
||||||
Welcome${name && name.trim() ? `, <span style="color: ${colors.primary};">${name.trim()}</span>` : ''}!
|
Welcome${name && name.trim() ? `, <span style="color: ${primaryColor};">${name.trim()}</span>` : ''}!
|
||||||
</h2>
|
</h2>
|
||||||
<p style="margin: 0 0 30px 0; color: #666666; font-size: 16px; line-height: 1.6;">
|
<p style="margin: 0 0 30px 0; color: #666666; font-size: 16px; line-height: 1.6;">
|
||||||
Thank you for joining BlindMaster! To electrify your blinds, please verify your email address 🥹
|
Thank you for joining BlindMaster! To electrify your blinds, please verify your email address 🥹
|
||||||
@@ -90,7 +77,7 @@ async function sendVerificationEmail(toEmail, token, name) {
|
|||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="padding: 0 40px 40px 40px;">
|
<td align="center" style="padding: 0 40px 40px 40px;">
|
||||||
<a href="${verificationLink}"
|
<a href="${verificationLink}"
|
||||||
style="display: inline-block; padding: 16px 48px; background: ${colors.gradient}; color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: bold; box-shadow: 0 4px 12px ${colors.shadow}; transition: all 0.3s ease;">
|
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
|
Verify Email Address
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -141,8 +128,8 @@ async function sendVerificationEmail(toEmail, token, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to send password reset email
|
// Helper function to send password reset email
|
||||||
async function sendPasswordResetEmail(toEmail, code, name) {
|
async function sendPasswordResetEmail(toEmail, code, name, localHour = new Date().getHours()) {
|
||||||
const colors = getColorForTime();
|
const primaryColor = getColorForTime(localHour);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info = await transporter.sendMail({
|
const info = await transporter.sendMail({
|
||||||
@@ -186,8 +173,8 @@ async function sendPasswordResetEmail(toEmail, code, name) {
|
|||||||
<!-- Code Display -->
|
<!-- Code Display -->
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="padding: 0 40px 40px 40px;">
|
<td align="center" style="padding: 0 40px 40px 40px;">
|
||||||
<div style="display: inline-block; padding: 20px 40px; background-color: #f9f9f9; border-radius: 8px; border: 2px solid ${colors.primary};">
|
<div style="display: inline-block; padding: 20px 40px; background-color: #f9f9f9; border-radius: 8px; border: 2px solid ${primaryColor};">
|
||||||
<p style="margin: 0; color: ${colors.primary}; font-size: 36px; font-weight: bold; letter-spacing: 8px; font-family: 'Courier New', monospace;">
|
<p style="margin: 0; color: ${primaryColor}; font-size: 36px; font-weight: bold; letter-spacing: 8px; font-family: 'Courier New', monospace;">
|
||||||
${code}
|
${code}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user