chore(unsubscribe): Merge backup/master unsubscribe handler in to staging (#17253)
This commit is contained in:
committed by
mrugesh mohapatra
parent
05176b8bd2
commit
cb15de32f5
@ -12,9 +12,8 @@ module.exports = function(app) {
|
|||||||
router.get('/api/github', githubCalls);
|
router.get('/api/github', githubCalls);
|
||||||
router.get('/chat', chat);
|
router.get('/chat', chat);
|
||||||
router.get('/twitch', twitch);
|
router.get('/twitch', twitch);
|
||||||
router.get('/unsubscribe/:email', unsubscribeAll);
|
router.get('/u/:email', unsubscribe);
|
||||||
router.get('/unsubscribe-notifications/:email', unsubscribeAll);
|
router.get('/unsubscribe/:email', unsubscribe);
|
||||||
router.get('/unsubscribe-quincy/:email', unsubscribeAll);
|
|
||||||
router.get('/submit-cat-photo', submitCatPhoto);
|
router.get('/submit-cat-photo', submitCatPhoto);
|
||||||
router.get(
|
router.get(
|
||||||
'/the-fastest-web-page-on-the-internet',
|
'/the-fastest-web-page-on-the-internet',
|
||||||
@ -121,30 +120,51 @@ module.exports = function(app) {
|
|||||||
res.redirect('https://twitch.tv/freecodecamp');
|
res.redirect('https://twitch.tv/freecodecamp');
|
||||||
}
|
}
|
||||||
|
|
||||||
function unsubscribeAll(req, res, next) {
|
function unsubscribe(req, res, next) {
|
||||||
req.checkParams('email', 'Must send a valid email').isEmail();
|
req.checkParams(
|
||||||
var query = { email: req.params.email };
|
'email',
|
||||||
var params = {
|
`"${req.params.email}" isn't a valid email address.`
|
||||||
sendQuincyEmail: false,
|
).isEmail();
|
||||||
sendMonthlyEmail: false,
|
const errors = req.validationErrors(true);
|
||||||
sendNotificationEmail: false
|
if (errors) {
|
||||||
};
|
req.flash('error', { msg: errors.email.msg });
|
||||||
return User.updateAll(query, params, function(err, info) {
|
return res.redirect('/');
|
||||||
if (err) { return next(err); }
|
|
||||||
if (info.count === 0) {
|
|
||||||
req.flash(
|
|
||||||
'info',
|
|
||||||
'Email address not found. ' +
|
|
||||||
'Please update your Email preferences from your profile.'
|
|
||||||
);
|
|
||||||
return res.redirect('/map');
|
|
||||||
} else {
|
|
||||||
req.flash(
|
|
||||||
'info',
|
|
||||||
'We\'ve successfully updated your Email preferences.'
|
|
||||||
);
|
|
||||||
return res.redirect('/unsubscribed');
|
|
||||||
}
|
}
|
||||||
|
return User.find({
|
||||||
|
where: {
|
||||||
|
email: req.params.email
|
||||||
|
}
|
||||||
|
}, (err, users) => {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
if (!users.length) {
|
||||||
|
req.flash('info', {
|
||||||
|
msg: 'Email address not found. Please update your Email ' +
|
||||||
|
'preferences from your settings.'
|
||||||
|
});
|
||||||
|
return res.redirect('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
const updates = users.map(user => {
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
user.updateAttributes({
|
||||||
|
sendQuincyEmail: false
|
||||||
|
}, (err) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return Promise.all(updates)
|
||||||
|
.then(() => {
|
||||||
|
req.flash('info', {
|
||||||
|
msg: 'We\'ve successfully updated your Email preferences.'
|
||||||
|
});
|
||||||
|
return res.redirect('/unsubscribed/' + req.params.email);
|
||||||
|
})
|
||||||
|
.catch(next);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user