Some fixes so that the subscription forms work with the new mailer
This commit is contained in:
parent
446d75ce71
commit
1f5566ca9b
5 changed files with 22 additions and 9 deletions
|
@ -65,11 +65,13 @@ hbs.registerPartials(__dirname + '/views/subscription/partials/');
|
||||||
* and the message is never displayed
|
* and the message is never displayed
|
||||||
*/
|
*/
|
||||||
hbs.registerHelper('flash_messages', function () { // eslint-disable-line prefer-arrow-callback
|
hbs.registerHelper('flash_messages', function () { // eslint-disable-line prefer-arrow-callback
|
||||||
|
console.log(this.flash);
|
||||||
if (typeof this.flash !== 'function') { // eslint-disable-line no-invalid-this
|
if (typeof this.flash !== 'function') { // eslint-disable-line no-invalid-this
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let messages = this.flash(); // eslint-disable-line no-invalid-this
|
let messages = this.flash(); // eslint-disable-line no-invalid-this
|
||||||
|
console.log(messages);
|
||||||
let response = [];
|
let response = [];
|
||||||
|
|
||||||
// group messages by type
|
// group messages by type
|
||||||
|
@ -185,9 +187,15 @@ function createApp(trusted) {
|
||||||
useWith404Fallback('/mailtrain', express.static(path.join(__dirname, 'client', 'dist')));
|
useWith404Fallback('/mailtrain', express.static(path.join(__dirname, 'client', 'dist')));
|
||||||
useWith404Fallback('/locales', express.static(path.join(__dirname, 'client', 'locales')));
|
useWith404Fallback('/locales', express.static(path.join(__dirname, 'client', 'locales')));
|
||||||
|
|
||||||
/* FIXME - can we remove this???
|
|
||||||
|
|
||||||
// make sure flash messages are available
|
// Make sure flash messages are available
|
||||||
|
// Currently, flash messages are used only from routes/subscription.js
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.locals.flash = req.flash.bind(req);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
/* FIXME - can we remove this???
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.locals.flash = req.flash.bind(req);
|
res.locals.flash = req.flash.bind(req);
|
||||||
res.locals.user = req.user;
|
res.locals.user = req.user;
|
||||||
|
|
|
@ -35,9 +35,13 @@ Handlebars.registerHelper('translate', function (context, options) { // eslint-d
|
||||||
|
|
||||||
const transports = new Map();
|
const transports = new Map();
|
||||||
|
|
||||||
async function getOrCreateMailer(sendConfiguration) {
|
async function getOrCreateMailer(sendConfigurationId) {
|
||||||
|
let sendConfiguration;
|
||||||
|
|
||||||
if (!sendConfiguration) {
|
if (!sendConfiguration) {
|
||||||
sendConfiguration = sendConfigurations.getSystemSendConfiguration();
|
sendConfiguration = await sendConfigurations.getSystemSendConfiguration();
|
||||||
|
} else {
|
||||||
|
sendConfiguration = await sendConfigurations.getById(contextHelpers.getAdminContext(), sendConfigurationId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transport = transports.get(sendConfiguration.id) || await _createTransport(sendConfiguration);
|
const transport = transports.get(sendConfiguration.id) || await _createTransport(sendConfiguration);
|
||||||
|
@ -65,8 +69,8 @@ async function _sendMail(transport, mail, template) {
|
||||||
|
|
||||||
const preparedHtml = await tools.prepareHtml(mail.html);
|
const preparedHtml = await tools.prepareHtml(mail.html);
|
||||||
|
|
||||||
if (prepareHtml) {
|
if (preparedHtml) {
|
||||||
mail.html = prepareHtml;
|
mail.html = preparedHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
const textRenderer = await tools.getTemplate(template.text);
|
const textRenderer = await tools.getTemplate(template.text);
|
||||||
|
|
|
@ -67,7 +67,7 @@ async function mergeTemplateIntoLayout(template, layout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.endsWith('.hbs')) {
|
if (template.endsWith('.hbs')) {
|
||||||
template = readFile(template);
|
template = await readFile(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const source = layout.replace(/\{\{\{body\}\}\}/g, template);
|
const source = layout.replace(/\{\{\{body\}\}\}/g, template);
|
||||||
|
@ -121,7 +121,7 @@ async function prepareHtml(html) {
|
||||||
FetchExternalResources: false, // disables resource loading over HTTP / filesystem
|
FetchExternalResources: false, // disables resource loading over HTTP / filesystem
|
||||||
ProcessExternalResources: false // do not execute JS within script blocks
|
ProcessExternalResources: false // do not execute JS within script blocks
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
const head = win.document.querySelector('head');
|
const head = win.document.querySelector('head');
|
||||||
let hasCharsetTag = false;
|
let hasCharsetTag = false;
|
||||||
|
|
|
@ -114,7 +114,7 @@ async function remove(context, id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSystemSendConfiguration() {
|
async function getSystemSendConfiguration() {
|
||||||
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId());
|
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -185,6 +185,7 @@ async function _renderSubscribe(req, res, list, subscription) {
|
||||||
|
|
||||||
data.isWeb = true;
|
data.isWeb = true;
|
||||||
data.needsJsWarning = true;
|
data.needsJsWarning = true;
|
||||||
|
|
||||||
data.flashMessages = await captureFlashMessages(res);
|
data.flashMessages = await captureFlashMessages(res);
|
||||||
|
|
||||||
const result = htmlRenderer(data);
|
const result = htmlRenderer(data);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue