factor out settings page with email settings

This commit is contained in:
Quincy Larson
2016-03-13 16:06:04 -07:00
parent 8e621fd0cb
commit d47aed4850
5 changed files with 176 additions and 55 deletions

View File

@@ -153,6 +153,21 @@ module.exports = function(app) {
sendNonUserToMap,
toggleLockdownMode
);
router.get(
'/toggle-announcement-email-mode',
sendNonUserToMap,
toggleReceivesAnnouncementEmails
);
router.get(
'/toggle-notification-email-mode',
sendNonUserToMap,
toggleReceivesNotificationEmails
);
router.get(
'/toggle-quincy-email-mode',
sendNonUserToMap,
toggleReceivesQuincyEmails
);
router.post(
'/account/delete',
ifNoUser401,
@@ -163,6 +178,11 @@ module.exports = function(app) {
sendNonUserToMap,
getAccount
);
router.get(
'/settings',
sendNonUserToMap,
getSettings
);
router.get('/vote1', vote1);
router.get('/vote2', vote2);
@@ -228,6 +248,10 @@ module.exports = function(app) {
return res.redirect('/' + username);
}
function getSettings(req, res, next) {
res.render('account/settings');
}
function returnUser(req, res, next) {
const username = req.params.username.toLowerCase();
const { user, path } = req;
@@ -406,7 +430,7 @@ module.exports = function(app) {
section at the bottom of this page.
`
});
return res.redirect('/' + req.user.username);
res.redirect('/settings');
});
}
req.user.isLocked = true;
@@ -420,7 +444,40 @@ module.exports = function(app) {
section at the bottom of this page.
`
});
return res.redirect('/' + req.user.username);
res.redirect('/settings');
});
}
function toggleReceivesAnnouncementEmails(req, res, next) {
return User.findById(req.accessToken.userId, function(err, user) {
if (err) { return next(err); }
user.updateAttribute('sendMonthlyEmail', typeof user.sendMonthlyEmail !== "undefined" ? !user.sendMonthlyEmail : true, function(err) {
if (err) { return next(err); }
req.flash('info', { msg: 'Email preferences updated successfully.' });
res.redirect('/settings');
});
});
}
function toggleReceivesQuincyEmails(req, res, next) {
return User.findById(req.accessToken.userId, function(err, user) {
if (err) { return next(err); }
user.updateAttribute('sendQuincyEmail', typeof user.sendQuincyEmail !== "undefined" ? !user.sendQuincyEmail : true, function(err) {
if (err) { return next(err); }
req.flash('info', { msg: 'Email preferences updated successfully.' });
res.redirect('/settings');
});
});
}
function toggleReceivesNotificationEmails(req, res, next) {
return User.findById(req.accessToken.userId, function(err, user) {
if (err) { return next(err); }
user.updateAttribute('sendNotificationEmail', typeof user.sendNotificationEmail !== "undefined" ? !user.sendNotificationEmail : true, function(err) {
if (err) { return next(err); }
req.flash('info', { msg: 'Email preferences updated successfully.' });
res.redirect('/settings');
});
});
}