Obsoleting some old files

Transition to SPA-style client
Basis for Mosaico template editor
This commit is contained in:
Tomas Bures 2018-02-25 20:54:15 +01:00
parent 7750232716
commit c85f2d4440
942 changed files with 86311 additions and 967 deletions

View file

@ -21,6 +21,7 @@ async function getAuthenticatedConfig(context) {
defaultCustomFormValues: await forms.getDefaultCustomFormValues(),
user: {
id: context.user.id,
username: context.user.username,
namespace: context.user.namespace
},
globalPermissions: shares.getGlobalPermissions(context),
@ -28,24 +29,8 @@ async function getAuthenticatedConfig(context) {
}
}
function registerRootRoute(router, entryPoint, title) {
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
const mailtrainConfig = await getAnonymousConfig(req.context);
if (req.user) {
Object.assign(mailtrainConfig, await getAuthenticatedConfig(req.context));
}
res.render('react-root', {
title,
reactEntryPoint: entryPoint,
reactCsrfToken: req.csrfToken(),
mailtrainConfig: JSON.stringify(mailtrainConfig)
});
});
}
module.exports = {
registerRootRoute,
getAuthenticatedConfig
getAuthenticatedConfig,
getAnonymousConfig
};

View file

@ -1,3 +1,5 @@
// DEPRECATED
'use strict';
let _ = require('../lib/translate')._;

View file

@ -1,22 +1,17 @@
'use strict';
let lists = require('./models/lists');
let fields = require('./models/fields');
let _ = require('./translate')._;
module.exports = {
getDefaultMergeTags,
getRSSMergeTags,
getListMergeTags,
rollbackAndReleaseConnection,
filterObject,
enforce,
cleanupFromPost
cleanupFromPost,
filterObject
};
function getDefaultMergeTags(callback) {
// Using a callback for the sake of future-proofness
callback(null, [{
function getDefaultMergeTags() {
return [{
key: 'LINK_UNSUBSCRIBE',
value: _('URL that points to the unsubscribe page')
}, {
@ -28,15 +23,6 @@ function getDefaultMergeTags(callback) {
}, {
key: 'EMAIL',
value: _('Email address')
}, {
key: 'FIRST_NAME',
value: _('First name')
}, {
key: 'LAST_NAME',
value: _('Last name')
}, {
key: 'FULL_NAME',
value: _('Full name (first and last name combined)')
}, {
key: 'SUBSCRIPTION_ID',
value: _('Unique ID that identifies the recipient')
@ -46,12 +32,11 @@ function getDefaultMergeTags(callback) {
}, {
key: 'CAMPAIGN_ID',
value: _('Unique ID that identifies current campaign')
}]);
}];
}
function getRSSMergeTags(callback) {
// Using a callback for the sake of future-proofness
callback(null, [{
function getRSSMergeTags() {
return [{
key: 'RSS_ENTRY',
value: _('content from an RSS entry')
}, {
@ -72,45 +57,17 @@ function getRSSMergeTags(callback) {
}, {
key: 'RSS_ENTRY_IMAGE_URL',
value: _('RSS entry image URL')
}]);
}];
}
function getListMergeTags(listId, callback) {
lists.get(listId, (err, list) => {
if (err) {
return callback(err);
}
if (!list) {
list = {
id: listId
};
}
fields.list(list.id, (err, fieldList) => {
if (err && !fieldList) {
fieldList = [];
}
let mergeTags = [];
fieldList.forEach(field => {
mergeTags.push({
key: field.key,
value: field.name
});
});
return callback(null, mergeTags);
});
});
function enforce(condition, message) {
if (!condition) {
throw new Error(message);
}
}
// FIXME - remove once we get rid of non-async models
function rollbackAndReleaseConnection(connection, callback) {
connection.rollback(() => {
connection.release();
return callback();
});
function cleanupFromPost(value) {
return (value || '').toString().trim();
}
function filterObject(obj, allowedKeys) {
@ -122,14 +79,4 @@ function filterObject(obj, allowedKeys) {
}
return result;
}
function enforce(condition, message) {
if (!condition) {
throw new Error(message);
}
}
function cleanupFromPost(value) {
return (value || '').toString().trim();
}

View file

@ -16,20 +16,53 @@ const { nodeifyFunction, nodeifyPromise } = require('./nodeify');
const interoperableErrors = require('../shared/interoperable-errors');
const contextHelpers = require('./context-helpers');
let LdapStrategy;
let authMode = 'local';
let LdapStrategy;
let ldapStrategyOpts;
if (config.ldap.enabled) {
if (config.ldap.method == 'ldapjs') {
if (!config.ldap.method || config.ldap.method == 'ldapjs') {
try {
LdapStrategy = require('passport-ldapjs').Strategy; // eslint-disable-line global-require
authMode = 'ldapjs';
log.info('LDAP', 'Found module "passport-ldapjs". It will be used for LDAP auth.');
ldapStrategyOpts = {
server: {
url: 'ldap://' + config.ldap.host + ':' + config.ldap.port
},
base: config.ldap.baseDN,
search: {
filter: config.ldap.filter,
attributes: [config.ldap.uidTag, config.ldap.nameTag, 'mail'],
scope: 'sub'
},
uidTag: config.ldap.uidTag,
bindUser: config.ldap.bindUser,
bindPassword: config.ldap.bindPassword
};
} catch (exc) {
log.info('LDAP', 'Module "passport-ldapjs" not installed. It will not be used for LDAP auth.');
}
} else if (config.ldap.method == 'ldapauth') {
}
if (!LdapStrategy && (!config.ldap.method || config.ldap.method == 'ldapauth')) {
try {
LdapStrategy = require('passport-ldapauth').Strategy; // eslint-disable-line global-require
authMode = 'ldapauth';
log.info('LDAP', 'Found module "passport-ldapauth". It will be used for LDAP auth.');
ldapStrategyOpts = {
server: {
url: 'ldap://' + config.ldap.host + ':' + config.ldap.port,
searchBase: config.ldap.baseDN,
searchFilter: config.ldap.filter,
searchAttributes: [config.ldap.uidTag, config.ldap.nameTag, 'mail'],
bindDN: config.ldap.bindUser,
bindCredentials: config.ldap.bindPassword
},
};
} catch (exc) {
log.info('LDAP', 'Module "passport-ldapauth" not installed. It will not be used for LDAP auth.');
}
@ -123,42 +156,12 @@ module.exports.restLogin = (req, res, next) => {
})(req, res, next);
};
if (authMode === 'ldapjs' || authMode === 'ldapauth') {
if (LdapStrategy) {
log.info('Using LDAP auth (passport-' + authMode + ')');
module.exports.authMethod = 'ldap';
module.exports.isAuthMethodLocal = false;
let opts;
if (authMode === 'ldapjs') {
opts = {
server: {
url: 'ldap://' + config.ldap.host + ':' + config.ldap.port
},
base: config.ldap.baseDN,
search: {
filter: config.ldap.filter,
attributes: [config.ldap.uidTag, config.ldap.nameTag, 'mail'],
scope: 'sub'
},
uidTag: config.ldap.uidTag,
bindUser: config.ldap.bindUser,
bindPassword: config.ldap.bindPassword
};
} else if (authMode = 'ldapauth') {
opts = {
server: {
url: 'ldap://' + config.ldap.host + ':' + config.ldap.port,
searchBase: config.ldap.baseDN,
searchFilter: config.ldap.filter,
searchAttributes: [config.ldap.uidTag, config.ldap.nameTag, 'mail'],
bindDN: config.ldap.bindUser,
bindCredentials: config.ldap.bindPassword
},
};
}
passport.use(new LdapStrategy(opts, nodeifyFunction(async (profile) => {
passport.use(new LdapStrategy(ldapStrategyOpts, nodeifyFunction(async (profile) => {
try {
const user = await users.getByUsername(profile[config.ldap.uidTag]);