behring-bjj-face-api / send-reset.js
FelipeFavalli's picture
Upload 15 files
98e9bb3 verified
Raw History Blame Contribute Delete
4.31 kB
const nodemailer = require('nodemailer');
exports.handler = async (event, context) => {
// Enable CORS
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'POST, OPTIONS'
};
if (event.httpMethod === 'OPTIONS') {
return { statusCode: 200, headers, body: '' };
}
if (event.httpMethod !== 'POST') {
return { statusCode: 405, headers, body: 'Method Not Allowed' };
}
try {
const { toEmail, studentName, resetLink } = JSON.parse(event.body);
if (!toEmail || !studentName || !resetLink) {
return {
statusCode: 400,
headers,
body: JSON.stringify({ error: 'Missing required parameters: toEmail, studentName, resetLink' })
};
}
const gmailUser = process.env.GMAIL_USER || 'projetobehringsports@gmail.com';
const gmailPass = process.env.GMAIL_PASS;
if (!gmailPass) {
return {
statusCode: 500,
headers,
body: JSON.stringify({
error: 'SMTP credentials missing. Please set GMAIL_PASS environment variable in Netlify dashboard.'
})
};
}
// Configure Nodemailer transporter with Gmail SMTP
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailUser,
pass: gmailPass
}
});
// HTML Email Template
const mailOptions = {
from: `"Behring Jiu-Jitsu" <${gmailUser}>`,
to: toEmail,
subject: 'Recuperação de Senha - Behring Jiu-Jitsu',
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 24px; background-color: #121212; color: #ffffff; border-radius: 8px; border: 2px solid #e05a00;">
<div style="text-align: center; margin-bottom: 24px;">
<h2 style="color: #e05a00; margin: 0; font-size: 24px; letter-spacing: 1px;">BEHRING JIU-JITSU</h2>
<span style="font-size: 12px; color: #888888; letter-spacing: 0.5px;">São Bento do Sapucaí</span>
</div>
<hr style="border: 0; border-top: 1px solid #222222; margin-bottom: 24px;">
<p style="font-size: 15px; line-height: 1.5; margin-bottom: 16px;">Olá, <strong>${studentName}</strong>,</p>
<p style="font-size: 14px; line-height: 1.6; color: #cccccc; margin-bottom: 24px;">
Recebemos uma solicitação para redefinir a senha da sua conta no aplicativo da Behring Jiu-Jitsu.
Para criar uma nova senha de acesso, clique no botão de redefinição abaixo:
</p>
<div style="text-align: center; margin: 32px 0;">
<a href="${resetLink}" style="background-color: #e05a00; color: #ffffff; text-decoration: none; padding: 14px 28px; font-weight: bold; border-radius: 6px; font-size: 15px; display: inline-block; box-shadow: 0 4px 12px rgba(224,90,0,0.3);">
Redefinir Minha Senha
</a>
</div>
<p style="font-size: 12px; line-height: 1.5; color: #666666; margin-top: 32px; border-top: 1px solid #222222; padding-top: 16px;">
Se você não solicitou a alteração de senha, pode ignorar este e-mail com segurança. O link é válido por tempo limitado.
</p>
</div>
`
};
await transporter.sendMail(mailOptions);
return {
statusCode: 200,
headers,
body: JSON.stringify({ message: 'Reset email sent successfully' })
};
} catch (error) {
console.error('Error sending reset email:', error);
return {
statusCode: 500,
headers,
body: JSON.stringify({ error: error.message || 'Error occurred while sending the email.' })
};
}
};