v1.7.0
This commit is contained in:
parent
bc902f8db7
commit
c26f8b15d7
6 changed files with 127 additions and 81 deletions
|
@ -114,26 +114,43 @@ router.post('/subscribe/:listId', (req, res) => {
|
|||
partial: true
|
||||
};
|
||||
|
||||
if (input.FORCE_SUBSCRIBE === 'yes') {
|
||||
if (/^(yes|true|1)$/i.test(input.FORCE_SUBSCRIBE)) {
|
||||
meta.status = 1;
|
||||
}
|
||||
|
||||
subscriptions.insert(list.id, meta, subscription, (err, response) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
res.status(200);
|
||||
res.json({
|
||||
data: {
|
||||
id: response.entryId,
|
||||
subscribed: true
|
||||
if (/^(yes|true|1)$/i.test(input.REQUIRE_CONFIRMATION)) {
|
||||
subscriptions.addConfirmation(list, input.EMAIL, subscription, (err, cid) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
res.status(200);
|
||||
res.json({
|
||||
data: {
|
||||
id: cid
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
subscriptions.insert(list.id, meta, subscription, (err, response) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
res.status(200);
|
||||
res.json({
|
||||
data: {
|
||||
id: response.cid
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -230,7 +230,7 @@ router.post('/:cid/subscribe', passport.parseForm, passport.csrfProtection, (req
|
|||
});
|
||||
data = tools.convertKeys(data);
|
||||
|
||||
subscriptions.addConfirmation(list.id, email, data, (err, confirmCid) => {
|
||||
subscriptions.addConfirmation(list, email, data, (err, confirmCid) => {
|
||||
if (!err && !confirmCid) {
|
||||
err = new Error('Could not store confirmation data');
|
||||
}
|
||||
|
@ -239,51 +239,7 @@ router.post('/:cid/subscribe', passport.parseForm, passport.csrfProtection, (req
|
|||
return res.redirect('/subscription/' + encodeURIComponent(req.params.cid) + '?' + tools.queryParams(req.body));
|
||||
}
|
||||
|
||||
fields.list(list.id, (err, fieldList) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
let encryptionKeys = [];
|
||||
fields.getRow(fieldList, data).forEach(field => {
|
||||
if (field.type === 'gpg' && field.value) {
|
||||
encryptionKeys.push(field.value.trim());
|
||||
}
|
||||
});
|
||||
|
||||
settings.list(['defaultHomepage', 'defaultFrom', 'defaultAddress', 'serviceUrl'], (err, configItems) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.redirect('/subscription/' + req.params.cid + '/confirm-notice');
|
||||
|
||||
mailer.sendMail({
|
||||
from: {
|
||||
name: configItems.defaultFrom,
|
||||
address: configItems.defaultAddress
|
||||
},
|
||||
to: {
|
||||
name: [].concat(data.firstName || []).concat(data.lastName || []).join(' '),
|
||||
address: email
|
||||
},
|
||||
subject: list.name + ': Please Confirm Subscription',
|
||||
encryptionKeys
|
||||
}, {
|
||||
html: 'emails/confirm-html.hbs',
|
||||
text: 'emails/confirm-text.hbs',
|
||||
data: {
|
||||
title: list.name,
|
||||
contactAddress: configItems.defaultAddress,
|
||||
confirmUrl: urllib.resolve(configItems.serviceUrl, '/subscription/subscribe/' + confirmCid)
|
||||
}
|
||||
}, err => {
|
||||
if (err) {
|
||||
log.error('Subscription', err.stack);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
res.redirect('/subscription/' + req.params.cid + '/confirm-notice');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue