Feature(settings): add user flag logic

This also moves a couple of settings to their own controller
This commit is contained in:
Berkeley Martinez
2016-07-16 10:38:06 -07:00
parent 991d86558a
commit 0d3dd75f41
16 changed files with 261 additions and 101 deletions

View File

@@ -155,26 +155,6 @@ module.exports = function(app) {
router.get('/email-signin', getEmailSignin);
router.get('/deprecated-signin', getDepSignin);
router.get('/update-email', getUpdateEmail);
api.get(
'/toggle-lockdown-mode',
sendNonUserToMap,
toggleLockdownMode
);
api.get(
'/toggle-announcement-email-mode',
sendNonUserToMap,
toggleReceivesAnnouncementEmails
);
api.get(
'/toggle-notification-email-mode',
sendNonUserToMap,
toggleReceivesNotificationEmails
);
api.get(
'/toggle-quincy-email-mode',
sendNonUserToMap,
toggleReceivesQuincyEmails
);
api.post(
'/account/delete',
ifNoUser401,
@@ -434,62 +414,6 @@ module.exports = function(app) {
);
}
function toggleLockdownMode(req, res, next) {
const { user } = req;
user.update$({ isLocked: !user.isLocked })
.subscribe(
() => {
req.flash('info', {
msg: 'We\'ve successfully updated your Privacy preferences.'
});
return res.redirect('/settings');
},
next
);
}
function toggleReceivesAnnouncementEmails(req, res, next) {
const { user } = req;
return user.update$({ sendMonthlyEmail: !user.sendMonthlyEmail })
.subscribe(
() => {
req.flash('info', {
msg: 'We\'ve successfully updated your Email preferences.'
});
return res.redirect('/settings');
},
next
);
}
function toggleReceivesQuincyEmails(req, res, next) {
const { user } = req;
return user.update$({ sendQuincyEmail: !user.sendQuincyEmail })
.subscribe(
() => {
req.flash('info', {
msg: 'We\'ve successfully updated your Email preferences.'
});
return res.redirect('/settings');
},
next
);
}
function toggleReceivesNotificationEmails(req, res, next) {
const { user } = req;
return user.update$({ sendNotificationEmail: !user.sendNotificationEmail })
.subscribe(
() => {
req.flash('info', {
msg: 'We\'ve successfully updated your Email preferences.'
});
return res.redirect('/settings');
},
next
);
}
function postDeleteAccount(req, res, next) {
User.destroyById(req.user.id, function(err) {
if (err) { return next(err); }