release: v2.11.2
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
const DEFAULT_ACCOUNT_EMAIL_TEMPLATES = {
|
||||
verificationSubject: 'Verify your Pulse Signage email address',
|
||||
verificationBody: 'Hello [[display_name]]!\n\nConfirm this email address:\n\n[[action_button]]\n\nThis link expires in 30 minutes.',
|
||||
verificationBody: 'Hello [b][[display_name]][/b]!\n[[action_button]]\nThis [u]link[/u] expires in [i][[expiry_time]][/i].\nConfirm this email address: [[url]]',
|
||||
resetSubject: 'Reset your Pulse Signage password',
|
||||
resetBody: 'Hello [[display_name]]!\n\nUse this link to choose a new password:\n\n[[action_button]]\n\nThis link expires in 30 minutes.'
|
||||
resetBody: 'Hello [b][[display_name]][/b]!\n[[action_button]]\nThis [u]link[/u] expires in [i][[expiry_time]][/i].\nChoose a new password: [[url]]'
|
||||
};
|
||||
|
||||
function formatAccountEmailExpiry(value, unit) {
|
||||
const amount = Number(value);
|
||||
const normalizedAmount = Number.isFinite(amount) && amount > 0 ? Math.round(amount) : 30;
|
||||
const normalizedUnit = unit === 'hours' ? 'hour' : 'minute';
|
||||
return normalizedAmount + ' ' + normalizedUnit + (normalizedAmount === 1 ? '' : 's');
|
||||
}
|
||||
|
||||
function renderAccountEmailTemplate(subject, body, variables) {
|
||||
const values = variables || {};
|
||||
const replaceVariables = function (value) {
|
||||
@@ -22,10 +29,11 @@ function renderAccountEmailTemplate(subject, body, variables) {
|
||||
const actionButton = actionUrl ? '<a href="' + actionUrl + '" style="display:inline-block;background:#111827;color:#ffffff;padding:12px 22px;text-decoration:none;border-radius:4px;font-weight:600;">' + actionLabel + '</a>' : '';
|
||||
const actionBlock = actionButton ? '<div style="margin:24px 0;text-align:' + actionAlignment + ';">' + actionButton + '</div>' : '';
|
||||
const plainLink = actionUrl ? '<a href="' + actionUrl + '">' + actionUrl + '</a>' : '';
|
||||
const escapedBodyUrl = values.url ? String(values.url).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') : '';
|
||||
const hasButtonPlaceholder = escapedBody.indexOf('[[action_button]]') !== -1;
|
||||
const hasUrlPlaceholder = String(body || '').indexOf('[[url]]') !== -1;
|
||||
const bodyWithAction = hasButtonPlaceholder
|
||||
? escapedBody.replace(/\[\[action_button\]\]/g, actionBlock)
|
||||
? escapedBody.split(escapedBodyUrl).join(plainLink).replace(/\[\[action_button\]\]/g, actionBlock).replace(/\[\[action_link\]\]/g, plainLink)
|
||||
: hasUrlPlaceholder
|
||||
? escapedBody.split(actionUrl).join(actionBlock + plainLink)
|
||||
: escapedBody.replace(/\[\[action_link\]\]/g, plainLink).replace(actionUrl, plainLink);
|
||||
@@ -43,4 +51,4 @@ function renderAccountEmailTemplate(subject, body, variables) {
|
||||
return { subject: renderedSubject, text: plainText, html: html };
|
||||
}
|
||||
|
||||
module.exports = { DEFAULT_ACCOUNT_EMAIL_TEMPLATES, renderAccountEmailTemplate };
|
||||
module.exports = { DEFAULT_ACCOUNT_EMAIL_TEMPLATES, formatAccountEmailExpiry, renderAccountEmailTemplate };
|
||||
|
||||
Reference in New Issue
Block a user