2017-07-08 13:48:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('./passport');
|
2017-07-08 18:32:04 +00:00
|
|
|
const config = require('config');
|
2017-07-24 04:03:32 +00:00
|
|
|
const permissions = require('./permissions');
|
2017-07-30 13:22:07 +00:00
|
|
|
const forms = require('../models/forms');
|
2017-08-13 18:11:58 +00:00
|
|
|
const shares = require('../models/shares');
|
2017-07-08 13:48:34 +00:00
|
|
|
|
2017-07-30 13:22:07 +00:00
|
|
|
async function getAnonymousConfig(context) {
|
2017-07-08 13:48:34 +00:00
|
|
|
return {
|
|
|
|
authMethod: passport.authMethod,
|
2017-07-08 18:32:04 +00:00
|
|
|
isAuthMethodLocal: passport.isAuthMethodLocal,
|
2017-07-09 13:41:53 +00:00
|
|
|
externalPasswordResetLink: config.ldap.passwordresetlink,
|
|
|
|
language: config.language || 'en',
|
2017-07-24 04:03:32 +00:00
|
|
|
isAuthenticated: !!context.user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-30 13:22:07 +00:00
|
|
|
async function getAuthenticatedConfig(context) {
|
2017-07-24 04:03:32 +00:00
|
|
|
return {
|
2017-07-30 13:22:07 +00:00
|
|
|
defaultCustomFormValues: await forms.getDefaultCustomFormValues(),
|
2017-09-17 14:36:23 +00:00
|
|
|
user: {
|
|
|
|
id: context.user.id,
|
|
|
|
namespace: context.user.namespace
|
|
|
|
},
|
2017-08-13 18:11:58 +00:00
|
|
|
globalPermissions: shares.getGlobalPermissions(context)
|
2017-07-08 13:48:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
function registerRootRoute(router, entryPoint, title) {
|
2017-07-30 13:22:07 +00:00
|
|
|
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
|
|
|
|
const mailtrainConfig = await getAnonymousConfig(req.context);
|
2017-07-24 04:03:32 +00:00
|
|
|
if (req.user) {
|
2017-07-30 13:22:07 +00:00
|
|
|
Object.assign(mailtrainConfig, await getAuthenticatedConfig(req.context));
|
2017-07-24 04:03:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 13:48:34 +00:00
|
|
|
res.render('react-root', {
|
|
|
|
title,
|
|
|
|
reactEntryPoint: entryPoint,
|
|
|
|
reactCsrfToken: req.csrfToken(),
|
2017-07-24 04:03:32 +00:00
|
|
|
mailtrainConfig: JSON.stringify(mailtrainConfig)
|
2017-07-08 13:48:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-07-30 13:22:07 +00:00
|
|
|
registerRootRoute,
|
2017-07-24 04:03:32 +00:00
|
|
|
getAuthenticatedConfig
|
2017-07-08 13:48:34 +00:00
|
|
|
};
|
|
|
|
|