mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:00 -04:00
Implemented mail translations. Updated debug output from translation.js
This commit is contained in:
@@ -10,6 +10,7 @@ const nodemailer = require('nodemailer');
|
||||
*/
|
||||
const variables = require('./variables');
|
||||
const log = require('./log');
|
||||
const translation = require('./translation');
|
||||
const qr = require('./qr');
|
||||
|
||||
/**
|
||||
@@ -47,12 +48,17 @@ module.exports = {
|
||||
*/
|
||||
send: (to, voucher) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// Create new translator
|
||||
const t = translation('en', 'email');
|
||||
|
||||
// Attempt to send mail via SMTP transport
|
||||
const result = await transport.sendMail({
|
||||
from: variables.smtpFrom,
|
||||
to: to,
|
||||
subject: 'WiFi Voucher Code',
|
||||
text: `Hi there,\n\nSomeone generated a WiFi Voucher, please use this code when connecting:\n\n${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`,
|
||||
subject: t('title'),
|
||||
text: `${t('greeting')},\n\n${t('intro')}:\n\n${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`,
|
||||
html: ejs.render(fs.readFileSync(`${__dirname}/../template/email/voucher.ejs`, 'utf-8'), {
|
||||
t,
|
||||
voucher,
|
||||
unifiSsid: variables.unifiSsid,
|
||||
unifiSsidPassword: variables.unifiSsidPassword,
|
||||
@@ -66,6 +72,7 @@ module.exports = {
|
||||
reject(`[Mail] ${e.message}`);
|
||||
});
|
||||
|
||||
// Check if the email was sent successfully
|
||||
if(result) {
|
||||
log.info(`[Mail] Sent to: ${to}`);
|
||||
resolve(true);
|
||||
|
||||
@@ -38,6 +38,6 @@ module.exports = (language = 'en', module) => {
|
||||
}
|
||||
|
||||
// Check if debugging is enabled. If enabled only return key
|
||||
return variables.translationDebug ? key : translations[key];
|
||||
return variables.translationDebug ? `%${key}%` : translations[key];
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user