Added API call to change the email address of an existing list subscriber
This commit is contained in:
parent
f661ba8a6b
commit
dd696d49ac
2 changed files with 136 additions and 1 deletions
107
routes/api.js
107
routes/api.js
|
@ -524,4 +524,111 @@ router.get('/blacklist/get', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
router.post('/changeemail/:listId', (req, res) => {
|
||||
let input = {};
|
||||
Object.keys(req.body).forEach(key => {
|
||||
input[(key || '').toString().trim().toUpperCase()] = (req.body[key] || '').toString().trim();
|
||||
});
|
||||
if (!(input.EMAILOLD) || (input.EMAILOLD === '')) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: 'EMAILOLD argument is required',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
if (!(input.EMAILNEW) || (input.EMAILNEW === '')) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: 'EMAILNEW argument is required',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
lists.getByCid(req.params.listId, (err, list) => {
|
||||
if (err) {
|
||||
log.error('API', err);
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
if (!list) {
|
||||
res.status(404);
|
||||
return res.json({
|
||||
error: 'Selected listId not found',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
blacklist.isblacklisted(input.EMAILNEW, (err, blacklisted) =>{
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
if (blacklisted) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: 'New email is blacklisted',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
subscriptions.getByEmail(list.id, input.EMAILOLD, (err, subscription) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
if (!subscription) {
|
||||
res.status(404);
|
||||
return res.json({
|
||||
error: 'Subscription with given old email not found',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
subscriptions.updateAddressCheck(list, subscription.cid, input.EMAILNEW, null, (err, old, valid) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: 'New email not valid',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
subscriptions.updateAddress(list.id, subscription.id, input.EMAILNEW, (err) => {
|
||||
if (err) {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
res.status(200);
|
||||
res.json({
|
||||
data: {
|
||||
id: subscription.id,
|
||||
changedemail: true
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue