mirror of
https://github.com/JuniorDark/RustyHearts-API.git
synced 2026-05-07 14:11:44 -04:00
Add project files.
This commit is contained in:
commit
0a12c6baa0
41 changed files with 2698 additions and 0 deletions
114
src/mailer/mailer.js
Normal file
114
src/mailer/mailer.js
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
const nodemailer = require('nodemailer');
|
||||
const handlebars = require('handlebars');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { mailerLogger } = require('../utils/logger');
|
||||
|
||||
// Load the email templates
|
||||
const emailTemplates = {
|
||||
confirmation: fs.readFileSync(path.join(__dirname, 'templates', 'confirmationTemplate.hbs'), 'utf-8'),
|
||||
verification: fs.readFileSync(path.join(__dirname, 'templates', 'verificationTemplate.hbs'), 'utf-8'),
|
||||
passwordReset: fs.readFileSync(path.join(__dirname, 'templates', 'passwordResetTemplate.hbs'), 'utf-8'),
|
||||
passwordChanged: fs.readFileSync(path.join(__dirname, 'templates', 'passwordChangedTemplate.hbs'), 'utf-8')
|
||||
};
|
||||
|
||||
// Compile the email templates
|
||||
const compiledTemplates = {
|
||||
confirmation: handlebars.compile(emailTemplates.confirmation),
|
||||
verification: handlebars.compile(emailTemplates.verification),
|
||||
passwordReset: handlebars.compile(emailTemplates.passwordReset),
|
||||
passwordChanged: handlebars.compile(emailTemplates.passwordChanged)
|
||||
};
|
||||
|
||||
// SMTP transport configuration
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: process.env.SMTP_PORT,
|
||||
secure: process.env.SMTP_ENCRYPTION === 'ssl' || process.env.SMTP_ENCRYPTION === 'tls',
|
||||
auth: {
|
||||
user: process.env.SMTP_USERNAME,
|
||||
pass: process.env.SMTP_PASSWORD
|
||||
}
|
||||
});
|
||||
|
||||
function sendConfirmationEmail(email, windyCode) {
|
||||
const template = compiledTemplates.confirmation;
|
||||
const emailContent = template({ windyCode });
|
||||
|
||||
const mailOptions = {
|
||||
from: `"${process.env.SMTP_FROMNAME}" <${process.env.SMTP_USERNAME}>`,
|
||||
to: email,
|
||||
subject: '[Rusty Hearts] Account Creation Confirmation',
|
||||
html: emailContent
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
mailerLogger.error('[Mailer] Error sending confirmation email: ' + error.message);
|
||||
} else {
|
||||
mailerLogger.info('[Mailer] Confirmation email sent: ' + info.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendVerificationEmail(email, verificationCode) {
|
||||
const template = compiledTemplates.verification;
|
||||
const emailContent = template({ verificationCode });
|
||||
|
||||
const mailOptions = {
|
||||
from: `"${process.env.SMTP_FROMNAME}" <${process.env.SMTP_USERNAME}>`,
|
||||
to: email,
|
||||
subject: '[Rusty Hearts] Account Creation',
|
||||
html: emailContent
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
mailerLogger.error('[Mailer] Error sending verification email: ' + error.message);
|
||||
} else {
|
||||
mailerLogger.info('[Mailer] Verification email sent: ' + info.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendPasswordResetEmail(email, verificationCode) {
|
||||
const template = compiledTemplates.passwordReset;
|
||||
const emailContent = template({ verificationCode });
|
||||
|
||||
const mailOptions = {
|
||||
from: `"${process.env.SMTP_FROMNAME}" <${process.env.SMTP_USERNAME}>`,
|
||||
to: email,
|
||||
subject: '[Rusty Hearts] Password Reset Request',
|
||||
html: emailContent
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
mailerLogger.error('[Mailer] Error sending password reset email: ' + error.message);
|
||||
} else {
|
||||
mailerLogger.info('[Mailer] Password reset email sent: ' + info.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendPasswordChangedEmail(email, windyCode) {
|
||||
const template = compiledTemplates.passwordChanged;
|
||||
const emailContent = template({ windyCode });
|
||||
|
||||
const mailOptions = {
|
||||
from: `"${process.env.SMTP_FROMNAME}" <${process.env.SMTP_USERNAME}>`,
|
||||
to: email,
|
||||
subject: '[Rusty Hearts] Account Password Changed',
|
||||
html: emailContent
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
mailerLogger.error('[Mailer] Error sending password changed email: ' + error.message);
|
||||
} else {
|
||||
mailerLogger.info('[Mailer] Password changed email sent: ' + info.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {sendConfirmationEmail, sendVerificationEmail, sendPasswordResetEmail, sendPasswordChangedEmail};
|
||||
14
src/mailer/templates/confirmationTemplate.hbs
Normal file
14
src/mailer/templates/confirmationTemplate.hbs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Welcome to Rusty Hearts!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Rusty Hearts</h1>
|
||||
<p>Dear {{windyCode}},</p>
|
||||
<p>Thank you for creating an account with Rusty Hearts! We are thrilled to have you as part of our community.</p>
|
||||
<p>You are now ready to login and start playing Rusty Hearts. As you embark on your journey, remember to have fun and enjoy the game!</p>
|
||||
<p>If you have any questions or need assistance with anything, please do not hesitate to contact our support team. We are always here to help you.</p>
|
||||
<p>Thank you again for choosing Rusty Hearts. We look forward to seeing you in the game!</p>
|
||||
<p>Best regards,<br>Rusty Hearts Team</p>
|
||||
</body>
|
||||
</html>
|
||||
16
src/mailer/templates/passwordChangedTemplate.hbs
Normal file
16
src/mailer/templates/passwordChangedTemplate.hbs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>[Rusty Hearts] Account Password Changed</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello, {{windyCode}}</p>
|
||||
<p>We're writing to let you know that the password for your Rusty Hearts account has been changed. If you made this change yourself, you can disregard this message.</p>
|
||||
<p>However, if you didn't change your password or if you're unsure if someone else has gained access to your account, we recommend taking immediate action to secure your account. Here are some steps you can take:</p>
|
||||
<ul>
|
||||
<li>Change your password again and make sure it's strong and unique</li>
|
||||
<li>Contact our support team if you need further assistance or if you believe your account has been compromised</li>
|
||||
</ul>
|
||||
<p>Best regards,<br>Rusty Hearts Team</p>
|
||||
</body>
|
||||
</html>
|
||||
17
src/mailer/templates/passwordResetTemplate.hbs
Normal file
17
src/mailer/templates/passwordResetTemplate.hbs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>[Rusty Hearts] Password Reset Request</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello {{windycode}},</p>
|
||||
<p>We received a request to reset your Rusty Hearts account password. To proceed with the password reset, please enter the verification code below:</p>
|
||||
<div style="background-color: #f2f2f2; border: 1px solid #000; padding: 10px;">
|
||||
{{verificationCode}}
|
||||
</div>
|
||||
<p>This code will expire in 10 minutes for security reasons. If you do not enter the code within this timeframe, you may need to request a new one.</p>
|
||||
<p>If you did not initiate this password reset or do not recognize this email, please disregard it and contact our support team immediately to protect your account.</p>
|
||||
<p>Thank you for playing Rusty Hearts!</p>
|
||||
<p>Best regards,<br>Rusty Hearts Team</p>
|
||||
</body>
|
||||
</html>
|
||||
17
src/mailer/templates/verificationTemplate.hbs
Normal file
17
src/mailer/templates/verificationTemplate.hbs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>[Rusty Hearts] Account Creation</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello,</p>
|
||||
<p>Thank you for registering your email address with your Rusty Hearts account. To complete the registration process, please enter the verification code below:</p>
|
||||
<div style="background-color: #f2f2f2; border: 1px solid #000; padding: 10px;">
|
||||
{{verificationCode}}
|
||||
</div>
|
||||
<p>This code will expire in 10 minutes for security reasons. If you do not enter the code within this timeframe, you may need to request a new one.</p>
|
||||
<p>If you did not initiate this registration or do not recognize this email, please disregard it and contact our support team immediately.</p>
|
||||
<p>Thank you for playing Rusty Hearts!</p>
|
||||
<p>Best regards,<br>Rusty Hearts Team</p>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue