diff --git a/src/assets/emails/confirmationTemplate.html b/src/assets/emails/confirmationTemplate.html
new file mode 100644
index 0000000..e8eebe2
--- /dev/null
+++ b/src/assets/emails/confirmationTemplate.html
@@ -0,0 +1,203 @@
+
+
+
+
+
+
+
+
+ Hello {{username}}! Your Pretendo Network ID activation is almost complete. Please click the link in this email to confirm your e-mail address and complete the activation process.
+
+
+
+
+
+
+
+
+ | |
+
+
+
+ | |
+
+
+
+
+
+
+
+
+
+ |
+
+
+ | |
+
+
+
+
+
+ | |
+
+
+
+ | |
+
+
+ |
+ Hello {{username}}!
+ |
+
+
+ | |
+
+
+ |
+ Your Pretendo Network ID activation is almost complete. Please click the link below to confirm your e-mail address and complete the activation process.
+ |
+
+
+ | |
+
+
+ |
+
+ Confirm email address
+
+ |
+
+
+ | |
+
+
+ |
+ You may also enter the following 6-digit code on your console:
+ |
+
+
+ | |
+
+
+ |
+ {{confirmation-code}}
+ |
+
+
+ | |
+
+
+ |
+ We hope you have fun using our services!
+ |
+
+
+ | |
+
+
+ |
+ The Pretendo Network team
+ |
+
+
+ | |
+
+
+ |
+ |
+
+
+ |
+
+
+ | |
+
+
+ |
+ Note: this email message was auto-generated, please do not respond. For further assistance, please join our Discord server.
+ |
+
+
+ | |
+
+
+ |
+
+
+ |
+ |
+
+
+ |
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/src/assets/emails/genericTemplate.html b/src/assets/emails/genericTemplate.html
new file mode 100644
index 0000000..5f189c9
--- /dev/null
+++ b/src/assets/emails/genericTemplate.html
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+ {{preview}}
+
+
+
+
+
+
+
+
+ | |
+
+
+
+ | |
+
+
+
+
+
+
+
+
+
+ |
+
+
+ | |
+
+
+
+
+
+ | |
+
+
+
+ | |
+
+
+ |
+ Dear {{username}},
+ |
+
+
+ | |
+
+
+ |
+ {{paragraph}}
+ |
+
+
+
+ | |
+
+
+ |
+ The Pretendo Network team
+ |
+
+
+ | |
+
+
+ |
+ |
+
+
+ |
+
+
+ | |
+
+
+ |
+ Note: this email message was auto-generated, please do not respond. For further assistance, please join our Discord server.
+ |
+
+
+ | |
+
+
+ |
+
+
+ |
+ |
+
+
+ |
+
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/src/assets/images/pretendo-wordmark-multicolor-purple+white.png b/src/assets/images/pretendo-wordmark-multicolor-purple+white.png
new file mode 100644
index 0000000..66c89d5
Binary files /dev/null and b/src/assets/images/pretendo-wordmark-multicolor-purple+white.png differ
diff --git a/src/assets/images/pretendo-wordmark-singlecolor-purple.png b/src/assets/images/pretendo-wordmark-singlecolor-purple.png
new file mode 100644
index 0000000..9903947
Binary files /dev/null and b/src/assets/images/pretendo-wordmark-singlecolor-purple.png differ
diff --git a/src/mailer.js b/src/mailer.js
index d8228e2..b4e5ce8 100644
--- a/src/mailer.js
+++ b/src/mailer.js
@@ -1,5 +1,9 @@
const nodemailer = require('nodemailer');
const { config, disabledFeatures } = require('./config-manager');
+const path = require('path');
+const fs = require("fs");
+const genericEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/genericTemplate.html'), 'utf8');
+const confirmationEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/confirmationTemplate.html'), 'utf8');
let transporter;
@@ -7,11 +11,51 @@ if (!disabledFeatures.email) {
transporter = nodemailer.createTransport(config.email);
}
+/**
+ @param {Object} options
+ @param {String} options.to The address to send the email to
+ @param {String} options.subject The subject of the email
+
+ @param {String} options.username The username of the user (shown in the greeting)
+ @param {String} options.preview The preview text of the email (shown in the inbox by the email client)
+ @param {String} options.text The text version of the email
+
+ @param {String} options.paragraph The main content of the email
+
+ @param {Object} options.confirmation Whether or not the email is a confirmation email
+ @param {String} options.confirmation.href The link to the confirmation page
+ @param {String} options.confirmation.code The confirmation code
+
+ @param {Object} options.link An object containing the link to be shown in the email
+ @param {String} options.link.href The URL of the link
+ @param {String} options.link.text The text of the link
+
+*/
async function sendMail(options) {
if (!disabledFeatures.email) {
- options.from = config.email.from;
+ const { to, subject, username, paragraph, preview, text, link, confirmation } = options;
+
+ let html = confirmation ? confirmationEmailTemplate : genericEmailTemplate;
- await transporter.sendMail(options);
+ html = html.replace(/{{username}}/g, username);
+ html = html.replace(/{{paragraph}}/g, paragraph);
+ html = html.replace(/{{preview}}/g, (preview || ""));
+ html = html.replace(/{{confirmation-href}}/g, (confirmation?.href || ""));
+ html = html.replace(/{{confirmation-code}}/g, (confirmation?.code || ""));
+
+ if (link) {
+ const { href, text } = link;
+
+ const button = `| |
| ${text} |
`
+ html = html.replace(//g, button);
+ }
+
+ await transporter.sendMail({
+ to,
+ subject,
+ text,
+ html
+ });
}
}
diff --git a/src/server.js b/src/server.js
index c4dcf6b..9372a3a 100644
--- a/src/server.js
+++ b/src/server.js
@@ -23,6 +23,7 @@ const nasc = require('./services/nasc');
const datastore = require('./services/datastore');
const api = require('./services/api');
const localcdn = require('./services/local-cdn');
+const assets = require('./services/assets');
// START APPLICATION
@@ -42,6 +43,7 @@ app.use(nasc);
app.use(datastore);
app.use(api);
app.use(localcdn);
+app.use(assets);
// 404 handler
logger.info('Creating 404 status handler');
diff --git a/src/services/assets/index.js b/src/services/assets/index.js
new file mode 100644
index 0000000..2059739
--- /dev/null
+++ b/src/services/assets/index.js
@@ -0,0 +1,22 @@
+// handles serving assets
+
+const express = require('express');
+const subdomain = require('express-subdomain');
+const logger = require('../../../logger');
+const path = require('path');
+
+// Router to handle the subdomain restriction
+const assets = express.Router();
+
+// Setup public folder
+logger.info('[assets] Setting up public folder');
+assets.use(express.static(path.join(__dirname, '../../assets')));
+
+// Main router for endpoints
+const router = express.Router();
+
+// Create subdomains
+logger.info('[conntest] Creating \'assets\' subdomain');
+router.use(subdomain('assets', assets));
+
+module.exports = router;
\ No newline at end of file
diff --git a/src/util.js b/src/util.js
index 5550a70..0050b38 100644
--- a/src/util.js
+++ b/src/util.js
@@ -250,15 +250,23 @@ async function sendConfirmationEmail(pnid) {
await mailer.sendMail({
to: pnid.get('email.address'),
subject: '[Pretendo Network] Please confirm your email address',
- html: `Hello,
Your Pretendo Network ID activation is almost complete.
Please click the link below to confirm your e-mail address and complete the activation process.
https://api.pretendo.cc/v1/email/verify?token=${pnid.get('identification.email_token')}
If you are unable to connect to the above URL, please enter the following confirmation code on the device to which your Prentendo Network ID is linked.
<<Confirmation code: ${pnid.get('identification.email_code')}>>`
+ username: pnid.get('username'),
+ confirmation: {
+ href: `https://api.pretendo.cc/v1/email/verify?token=${pnid.get('identification.email_token')}`,
+ code: pnid.get('identification.email_code')
+ },
+ text: `Hello ${pnid.get('username')}! \r\n\r\nYour Pretendo Network ID activation is almost complete. Please click the link to confirm your e-mail address and complete the activation process: \r\nhttps://api.pretendo.cc/v1/email/verify?token=${pnid.get('identification.email_token')} \r\n\r\nYou may also enter the following 6-digit code on your console: ${pnid.get('identification.email_code')}`
});
+
}
async function sendEmailConfirmedEmail(pnid) {
await mailer.sendMail({
to: pnid.get('email.address'),
subject: '[Pretendo Network] Email address confirmed',
- html: 'Your email address has been confirmed!'
+ username: pnid.get('username'),
+ paragraph: 'your email address has been confirmed. We hope you have fun on Pretendo Network!',
+ text: `Dear ${pnid.get('username')}, \r\n\r\nYour email address has been confirmed. We hope you have fun on Pretendo Network!`
});
}
@@ -285,7 +293,13 @@ async function sendForgotPasswordEmail(pnid) {
await mailer.sendMail({
to: pnid.get('email.address'),
subject: '[Pretendo Network] Forgot Password',
- html: `Visit this link to reset your password ${config.website_base}/account/reset-password?token=${encodeURIComponent(passwordResetToken)}`
+ username: pnid.get('username'),
+ paragraph: 'a password reset has been requested from this account. If you did not request the password reset, please ignore this email. If you did request this password reset, please click the link below to reset your password.',
+ link: {
+ text: 'Reset password',
+ href: `${config.website_base}/account/reset-password?token=${encodeURIComponent(passwordResetToken)}`
+ },
+ text: `Dear ${pnid.get('username')}, a password reset has been requested from this account. \r\n\r\nIf you did not request the password reset, please ignore this email. \r\nIf you did request this password reset, please click the link to reset your password: ${config.website_base}/account/reset-password?token=${encodeURIComponent(passwordResetToken)}`
});
}