Merge branch 'master' of github.com:Mailtrain-org/mailtrain
This commit is contained in:
commit
6f554038c9
61 changed files with 2497 additions and 707 deletions
|
@ -1,12 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
let config = require('config');
|
||||
let express = require('express');
|
||||
let router = new express.Router();
|
||||
let passport = require('../lib/passport');
|
||||
let fs = require('fs');
|
||||
let path = require('path');
|
||||
let editorHelpers = require('../lib/editor-helpers.js')
|
||||
const config = require('config');
|
||||
const express = require('express');
|
||||
const router = new express.Router();
|
||||
const passport = require('../lib/passport');
|
||||
const _ = require('../lib/translate')._;
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const editorHelpers = require('../lib/editor-helpers')
|
||||
|
||||
router.all('/*', (req, res, next) => {
|
||||
if (!req.user) {
|
||||
|
@ -23,28 +24,38 @@ router.get('/editor', passport.csrfProtection, (req, res) => {
|
|||
return res.redirect('/');
|
||||
}
|
||||
|
||||
resource.editorName = resource.editorName || 'grapejs';
|
||||
resource.editorData = !resource.editorData ?
|
||||
{
|
||||
try {
|
||||
resource.editorData = JSON.parse(resource.editorData);
|
||||
} catch (err) {
|
||||
resource.editorData = {
|
||||
template: req.query.template || 'demo'
|
||||
} :
|
||||
JSON.parse(resource.editorData);
|
||||
}
|
||||
}
|
||||
|
||||
if (!resource.html && !resource.editorData.html) {
|
||||
if (!resource.html && !resource.editorData.html && !resource.editorData.mjml) {
|
||||
const base = path.join(__dirname, '..', 'public', 'grapejs', 'templates', resource.editorData.template);
|
||||
try {
|
||||
let file = path.join(__dirname, '..', 'public', 'grapejs', 'templates', resource.editorData.template, 'index.html');
|
||||
resource.html = fs.readFileSync(file, 'utf8');
|
||||
resource.editorData.mjml = fs.readFileSync(path.join(base, 'index.mjml'), 'utf8');
|
||||
} catch (err) {
|
||||
resource.html = err.message || err;
|
||||
try {
|
||||
resource.html = fs.readFileSync(path.join(base, 'index.html'), 'utf8');
|
||||
} catch (err) {
|
||||
resource.html = err.message || err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.render('grapejs/editor', {
|
||||
layout: 'grapejs/layout-editor',
|
||||
type: req.query.type,
|
||||
stringifiedResource: JSON.stringify(resource),
|
||||
resource,
|
||||
editorConfig: config.grapejs,
|
||||
csrfToken: req.csrfToken(),
|
||||
editor: {
|
||||
name: resource.editorName || 'grapejs',
|
||||
mode: resource.editorData.mjml ? 'mjml' : 'html',
|
||||
config: config.grapejs
|
||||
},
|
||||
csrfToken: req.csrfToken()
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -702,7 +702,12 @@ router.get('/:lcid/unsubscribe/:ucid', passport.csrfProtection, (req, res, next)
|
|||
}
|
||||
|
||||
|
||||
if (req.query.formTest ||
|
||||
const autoUnsubscribe = req.query.auto === 'yes';
|
||||
|
||||
if (autoUnsubscribe) {
|
||||
handleUnsubscribe(list, subscription, autoUnsubscribe, req.query.c, req.ip, res, next);
|
||||
|
||||
} else if (req.query.formTest ||
|
||||
list.unsubscriptionMode === lists.UnsubscriptionMode.ONE_STEP_WITH_FORM ||
|
||||
list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP_WITH_FORM) {
|
||||
|
||||
|
@ -741,7 +746,7 @@ router.get('/:lcid/unsubscribe/:ucid', passport.csrfProtection, (req, res, next)
|
|||
});
|
||||
});
|
||||
} else { // UnsubscriptionMode.ONE_STEP || UnsubscriptionMode.TWO_STEP || UnsubscriptionMode.MANUAL
|
||||
handleUnsubscribe(list, subscription, req.query.c, req.ip, res, next);
|
||||
handleUnsubscribe(list, subscription, autoUnsubscribe, req.query.c, req.ip, res, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -771,14 +776,32 @@ router.post('/:lcid/unsubscribe', passport.parseForm, passport.csrfProtection, (
|
|||
return next(err);
|
||||
}
|
||||
|
||||
handleUnsubscribe(list, subscription, campaignId, req.ip, res, next);
|
||||
handleUnsubscribe(list, subscription, false, campaignId, req.ip, res, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function handleUnsubscribe(list, subscription, campaignId, ip, res, next) {
|
||||
if (list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP ||
|
||||
list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP_WITH_FORM) {
|
||||
function handleUnsubscribe(list, subscription, autoUnsubscribe, campaignId, ip, res, next) {
|
||||
if ((list.unsubscriptionMode === lists.UnsubscriptionMode.ONE_STEP || list.unsubscriptionMode === lists.UnsubscriptionMode.ONE_STEP_WITH_FORM) ||
|
||||
(autoUnsubscribe && (list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP || list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP_WITH_FORM)) ) {
|
||||
|
||||
subscriptions.changeStatus(list.id, subscription.id, campaignId, subscriptions.Status.UNSUBSCRIBED, (err, found) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// TODO: Shall we do anything with "found"?
|
||||
|
||||
mailHelpers.sendUnsubscriptionConfirmed(list, subscription.email, subscription, err => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.redirect('/subscription/' + list.cid + '/unsubscribed-notice');
|
||||
});
|
||||
});
|
||||
|
||||
} else if (list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP || list.unsubscriptionMode === lists.UnsubscriptionMode.TWO_STEP_WITH_FORM) {
|
||||
|
||||
const data = {
|
||||
subscriptionId: subscription.id,
|
||||
|
@ -799,24 +822,6 @@ function handleUnsubscribe(list, subscription, campaignId, ip, res, next) {
|
|||
});
|
||||
});
|
||||
|
||||
} else if (list.unsubscriptionMode === lists.UnsubscriptionMode.ONE_STEP ||
|
||||
list.unsubscriptionMode === lists.UnsubscriptionMode.ONE_STEP_WITH_FORM) {
|
||||
|
||||
subscriptions.changeStatus(list.id, subscription.id, campaignId, subscriptions.Status.UNSUBSCRIBED, (err, found) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// TODO: Shall we do anything with "found"?
|
||||
|
||||
mailHelpers.sendUnsubscriptionConfirmed(list, subscription.email, subscription, err => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.redirect('/subscription/' + list.cid + '/unsubscribed-notice');
|
||||
});
|
||||
});
|
||||
} else { // UnsubscriptionMode.MANUAL
|
||||
res.redirect('/subscription/' + list.cid + '/manual-unsubscribe-notice');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue