add resubscribe functionality
parent
302d37e3d7
commit
505778acbf
|
@ -17,7 +17,10 @@ module.exports = function(app) {
|
|||
router.get('/unsubscribe/:email', unsubscribeMonthly);
|
||||
router.get('/unsubscribe-notifications/:email', unsubscribeNotifications);
|
||||
router.get('/unsubscribe-quincy/:email', unsubscribeQuincy);
|
||||
router.get('/unsubscribed/:email', unsubscribed);
|
||||
router.get('/unsubscribed', unsubscribed);
|
||||
router.get('/resubscribe/:email', resubscribe);
|
||||
router.get('/resubscribe', resubscribe);
|
||||
router.get('/get-started', getStarted);
|
||||
router.get('/submit-cat-photo', submitCatPhoto);
|
||||
router.get('/stories', showTestimonials);
|
||||
|
@ -173,7 +176,15 @@ module.exports = function(app) {
|
|||
}
|
||||
|
||||
function unsubscribeMonthly(req, res, next) {
|
||||
req.checkParams('email', 'Must send a valid email').isEmail();
|
||||
req.checkParams(
|
||||
'email',
|
||||
`"${req.params.email}" isn't a valid email address.`
|
||||
).isEmail();
|
||||
const errors = req.validationErrors(true);
|
||||
if (errors) {
|
||||
req.flash('error', { msg: errors.email.msg });
|
||||
return res.redirect('/map');
|
||||
}
|
||||
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
|
@ -192,13 +203,21 @@ module.exports = function(app) {
|
|||
req.flash('info', {
|
||||
msg: 'We\'ve successfully updated your Email preferences.'
|
||||
});
|
||||
return res.redirect('/unsubscribed');
|
||||
return res.redirect('/unsubscribed/' + req.params.email);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function unsubscribeNotifications(req, res, next) {
|
||||
req.checkParams('email', 'Must send a valid email').isEmail();
|
||||
req.checkParams(
|
||||
'email',
|
||||
`"${req.params.email}" isn't a valid email address.`
|
||||
).isEmail();
|
||||
const errors = req.validationErrors(true);
|
||||
if (errors) {
|
||||
req.flash('error', { msg: errors.email.msg });
|
||||
return res.redirect('/map');
|
||||
}
|
||||
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
|
@ -219,7 +238,15 @@ module.exports = function(app) {
|
|||
}
|
||||
|
||||
function unsubscribeQuincy(req, res, next) {
|
||||
req.checkParams('email', 'Must send a valid email').isEmail();
|
||||
req.checkParams(
|
||||
'email',
|
||||
`"${req.params.email}" isn't a valid email address.`
|
||||
).isEmail();
|
||||
const errors = req.validationErrors(true);
|
||||
if (errors) {
|
||||
req.flash('error', { msg: errors.email.msg });
|
||||
return res.redirect('/map');
|
||||
}
|
||||
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
|
@ -244,11 +271,47 @@ module.exports = function(app) {
|
|||
}
|
||||
|
||||
function unsubscribed(req, res) {
|
||||
req.checkParams('email', 'Must send a valid email').isEmail();
|
||||
res.render('resources/unsubscribed', {
|
||||
title: 'You have been unsubscribed'
|
||||
title: 'You have been unsubscribed',
|
||||
email: req.params.email
|
||||
});
|
||||
}
|
||||
|
||||
function resubscribe(req, res, next) {
|
||||
req.checkParams(
|
||||
'email',
|
||||
`"${req.params.email}" isn't a valid email address.`
|
||||
).isEmail();
|
||||
const errors = req.validationErrors(true);
|
||||
if (errors) {
|
||||
req.flash('error', { msg: errors.email.msg });
|
||||
return res.redirect('/map');
|
||||
}
|
||||
return User.findOne({ where: { email: req.params.email } }, (err, user) => {
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
req.flash('info', {
|
||||
msg: 'Email address not found. ' +
|
||||
'Please update your Email preferences from your profile.'
|
||||
});
|
||||
return res.redirect('/map');
|
||||
}
|
||||
return user.updateAttributes({
|
||||
sendMonthlyEmail: true,
|
||||
sendQuincyEmail: true,
|
||||
sendNotificationEmail: true
|
||||
}, (err) => {
|
||||
if (err) { return next(err); }
|
||||
req.flash('info', {
|
||||
msg: 'We\'ve successfully updated your Email preferences.'
|
||||
});
|
||||
return res.redirect('/map');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getStarted(req, res) {
|
||||
res.render('resources/get-started', {
|
||||
title: 'How to get started with Free Code Camp'
|
||||
|
|
|
@ -2,5 +2,14 @@ extends ../layout
|
|||
block content
|
||||
.panel.panel-info
|
||||
.panel-body.text-center
|
||||
h1 You have successfully been unsubscribed.
|
||||
h2 Whatever you do, keep coding! :)
|
||||
h1 OK - you have unsubscribed.
|
||||
h2 I (Quincy) may have sent you duplicate emails.
|
||||
h2 There was a bug in my emailing script.
|
||||
h2 I'm really sorry for the trouble.
|
||||
h2 This should be a one-time issue.
|
||||
h2 Do you want to re-subscribe?
|
||||
.big-break
|
||||
a.btn.btn-cta.signup-btn(href='/resubscribe/#{email}') Re-subscribe
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue