From d47aed485021ad9b2dd2c011a22616b41c11dfea Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Sun, 13 Mar 2016 16:06:04 -0700 Subject: [PATCH 1/7] factor out settings page with email settings --- client/less/main.less | 4 ++ common/models/user.json | 8 +++ server/boot/user.js | 61 ++++++++++++++++- server/views/account/settings.jade | 104 +++++++++++++++++++++++++++++ server/views/account/show.jade | 54 +-------------- 5 files changed, 176 insertions(+), 55 deletions(-) create mode 100644 server/views/account/settings.jade diff --git a/client/less/main.less b/client/less/main.less index 8ae2225ba5..9170725425 100644 --- a/client/less/main.less +++ b/client/less/main.less @@ -170,6 +170,10 @@ ul { margin-top: 15px; } +.positive-20 { + margin-top: 20px; +} + .positive-15-bottom { margin-bottom: 15px; } diff --git a/common/models/user.json b/common/models/user.json index 4aa16172f0..f696b49102 100644 --- a/common/models/user.json +++ b/common/models/user.json @@ -110,6 +110,14 @@ "type": "boolean", "default": true }, + "sendNotificationEmail": { + "type": "boolean", + "default": true + }, + "sendQuincyEmail": { + "type": "boolean", + "default": true + }, "isLocked": { "type": "boolean", "default": false, diff --git a/server/boot/user.js b/server/boot/user.js index 8af387b323..6a8308052f 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -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'); + }); }); } diff --git a/server/views/account/settings.jade b/server/views/account/settings.jade new file mode 100644 index 0000000000..1b810118d3 --- /dev/null +++ b/server/views/account/settings.jade @@ -0,0 +1,104 @@ +extends ../layout +block content + h1.text-center Settings for your Account + hr + h2.text-center Actions + .row + .col-xs-12 + a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/logout') + | Sign me out of Free Code Camp + .col-xs-12 + a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='mailto:team@freecodecamp.com') + | Email us at team@freecodecamp.com + .spacer + h2.text-center Account Settings + .row + .col-xs-12 + a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/commit') + | Edit my pledge + .spacer + h2.text-center Privacy Settings + .row + .col-xs-12.col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3 + .row + .col-xs-9 + p.large-p Make all of my solutions private + br + | (this disables your certificates) + if (user.isLocked) + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.active.positive-20(href='/toggle-lockdown-mode') On + else + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.positive-20(href='/toggle-lockdown-mode') Off + + .spacer + h2.text-center Email settings + .row + .col-xs-12.col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3 + .row + .col-xs-9 + p.large-p Send me announcement emails + br + | (we'll send you these every Thursday) + if (user.sendMonthlyEmail) + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.active.positive-20(href='/toggle-announcement-email-mode') On + else + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.positive-20(href='/toggle-announcement-email-mode') Off + + .row + .col-xs-9 + p.large-p Send me notification emails + br + | (these will pertain to your account) + if (user.sendNotificationEmail) + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.active.positive-20(href='/toggle-notification-email-mode') On + else + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.positive-20(href='/toggle-notification-email-mode') Off + + .row + .col-xs-9 + p.large-p Send me Quincy's weekly email + br + | (with new articles every Tuesday) + if (user.sendQuincyEmail) + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.active.positive-20(href='/toggle-quincy-email-mode') On + else + .col-xs-3 + a.btn.btn-lg.btn-primary.btn-block.positive-20(href='/toggle-quincy-email-mode') Off + + .spacer + h2.text-center Danger Zone + .row + .col-xs-12 + a.btn.btn-lg.btn-block.btn-danger.btn-link-social.confirm-deletion + | Delete my Free Code Camp account + script. + $('.confirm-deletion').on("click", function () { + $('#modal-dialog').modal('show'); + }); + #modal-dialog.modal.animated.wobble + .modal-dialog + .modal-content + .modal-header + a.close(href='#', data-dismiss='modal', aria-hidden='true') × + h3 You don't really want to delete your account, do you? + .modal-body + p This will really delete all your data, including all your progress, news stories and brownie points. + p We won't be able to recover any of it for you later, even if you change your mind. + p If there's something we could do better, send us an email instead and we'll do our best:   + a(href="mailto:team@freecodecamp.com") team@freecodecamp.com + | . + .modal-footer + a.btn.btn-success.btn-block(href='#', data-dismiss='modal', aria-hidden='true') + | Nevermind, I don't want to delete all of my progress + .spacer + form(action='/account/delete', method='POST') + input(type='hidden', name='_csrf', value=_csrf) + button.btn.btn-danger.btn-block(type='submit') + | I am 100% sure I want to delete my account and all of my progress \ No newline at end of file diff --git a/server/views/account/show.jade b/server/views/account/show.jade index 8d3e4bc576..c7c3050ffb 100644 --- a/server/views/account/show.jade +++ b/server/views/account/show.jade @@ -187,56 +187,4 @@ block content if (challenge.solution) a(href='/challenges/' + removeOldTerms(challenge.name) + '?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank')= removeOldTerms(challenge.name) else - a(href='/challenges/' + removeOldTerms(challenge.name))= removeOldTerms(challenge.name) - - if (user && user.username === username) - h1.text-center Manage your account - hr - .col-xs-12 - a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/logout') - | Sign me out of Free Code Camp - .col-xs-12 - a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='mailto:team@freecodecamp.com') - | Email us at team@freecodecamp.com - if (!user.isLocked) - .col-xs-12 - a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/toggle-lockdown-mode') - | Hide all my solutions from other people - br - | (this will disable your certificates) - else - .col-xs-12 - a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/toggle-lockdown-mode') - | Let other people see all my solutions - br - | (this will enable your certificates) - .col-xs-12 - a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/commit') - | Edit my pledge - .col-xs-12 - a.btn.btn-lg.btn-block.btn-danger.btn-link-social.confirm-deletion - | Delete my Free Code Camp account - script. - $('.confirm-deletion').on("click", function () { - $('#modal-dialog').modal('show'); - }); - #modal-dialog.modal.animated.wobble - .modal-dialog - .modal-content - .modal-header - a.close(href='#', data-dismiss='modal', aria-hidden='true') × - h3 You don't really want to delete your account, do you? - .modal-body - p This will really delete all your data, including all your progress, news stories and brownie points. - p We won't be able to recover any of it for you later, even if you change your mind. - p If there's something we could do better, send us an email instead and we'll do our best:   - a(href="mailto:team@freecodecamp.com") team@freecodecamp.com - | . - .modal-footer - a.btn.btn-success.btn-block(href='#', data-dismiss='modal', aria-hidden='true') - | Nevermind, I don't want to delete all of my progress - .spacer - form(action='/account/delete', method='POST') - input(type='hidden', name='_csrf', value=_csrf) - button.btn.btn-danger.btn-block(type='submit') - | I am 100% sure I want to delete my account and all of my progress + a(href='/challenges/' + removeOldTerms(challenge.name))= removeOldTerms(challenge.name) \ No newline at end of file From 2285d1826083412f833fecb787de852835349d98 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Sun, 13 Mar 2016 16:57:39 -0700 Subject: [PATCH 2/7] refactor show view to have a settings button --- server/views/account/settings.jade | 27 ++++++++++++++++++++++- server/views/account/show.jade | 35 +++++++----------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/server/views/account/settings.jade b/server/views/account/settings.jade index 1b810118d3..f7b8d70b05 100644 --- a/server/views/account/settings.jade +++ b/server/views/account/settings.jade @@ -2,8 +2,33 @@ extends ../layout block content h1.text-center Settings for your Account hr - h2.text-center Actions + h2.text-center Actions .row + .col-xs-12 + if (!user.isGithubCool) + a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github') + i.fa.fa-github + | Link my GitHub to unlock my portfolio + else + a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github') + i.fa.fa-github + | Update my portfolio from GitHub + if (!user.twitter) + a.btn.btn-lg.btn-block.btn-twitter.btn-link-social(href='/link/twitter') + i.fa.fa-twitter + | Add my Twitter to my portfolio + if (!user.facebook) + a.btn.btn-lg.btn-block.btn-facebook.btn-link-social(href='/link/facebook') + i.fa.fa-facebook + | Add my Facebook to my portfolio + if (!user.linkedin) + a.btn.btn-lg.btn-block.btn-linkedin.btn-link-social(href='/link/linkedin') + i.fa.fa-linkedin + | Add my LinkedIn to my portfolio + if (!user.google) + a.btn.btn-lg.btn-block.btn-google-plus.btn-link-social(href='/link/google') + i.fa.fa-google-plus + | Add my Google+ to my portfolio .col-xs-12 a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/logout') | Sign me out of Free Code Camp diff --git a/server/views/account/show.jade b/server/views/account/show.jade index c7c3050ffb..9297d4cc60 100644 --- a/server/views/account/show.jade +++ b/server/views/account/show.jade @@ -4,33 +4,14 @@ block content script. var challengeName = 'Profile View'; if (user && user.username === username) - h1.text-center Update your code portfolio - .row - .col-xs-12 - if (!user.isGithubCool) - a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github') - i.fa.fa-github - | Link my GitHub to unlock my portfolio - else - a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github') - i.fa.fa-github - | Update my portfolio from GitHub - if (!user.twitter) - a.btn.btn-lg.btn-block.btn-twitter.btn-link-social(href='/link/twitter') - i.fa.fa-twitter - | Add my Twitter to my portfolio - if (!user.facebook) - a.btn.btn-lg.btn-block.btn-facebook.btn-link-social(href='/link/facebook') - i.fa.fa-facebook - | Add my Facebook to my portfolio - if (!user.linkedin) - a.btn.btn-lg.btn-block.btn-linkedin.btn-link-social(href='/link/linkedin') - i.fa.fa-linkedin - | Add my LinkedIn to my portfolio - if (!user.google) - a.btn.btn-lg.btn-block.btn-google-plus.btn-link-social(href='/link/google') - i.fa.fa-google-plus - | Add my Google+ to my portfolio + .row + if (!user.isGithubCool) + a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github') + i.fa.fa-github + | Link my GitHub to unlock my portfolio + .col-xs-12 + a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/settings') + | Update your settings .spacer h1.text-center #{username}'s code portfolio hr From f16234d9c6d7dd0171da56b976b1276a668f9233 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Sun, 13 Mar 2016 16:58:08 -0700 Subject: [PATCH 3/7] refactor make account private action to use updateAttribute instead of save --- server/boot/user.js | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/server/boot/user.js b/server/boot/user.js index 6a8308052f..3da0486f87 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -418,33 +418,13 @@ module.exports = function(app) { } function toggleLockdownMode(req, res, next) { - if (req.user.isLocked === true) { - req.user.isLocked = false; - return req.user.save(function(err) { + return User.findById(req.accessToken.userId, function(err, user) { + if (err) { return next(err); } + user.updateAttribute('isLocked', typeof user.isLocked !== "undefined" ? !user.isLocked : true, function(err) { if (err) { return next(err); } - - req.flash('success', { - msg: dedent` - Other people can now view all your challenge solutions. - You can change this back at any time in the "Manage My Account" - section at the bottom of this page. - ` - }); + req.flash('info', { msg: 'Privacy preferences updated successfully.' }); res.redirect('/settings'); }); - } - req.user.isLocked = true; - return req.user.save(function(err) { - if (err) { return next(err); } - - req.flash('success', { - msg: dedent` - All your challenge solutions are now hidden from other people. - You can change this back at any time in the "Manage My Account" - section at the bottom of this page. - ` - }); - res.redirect('/settings'); }); } From 71b213d7d410d14e6a064d7dda2151b1ee524047 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Mon, 14 Mar 2016 23:54:59 -0700 Subject: [PATCH 4/7] make notification text more friendly --- server/boot/user.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/boot/user.js b/server/boot/user.js index 3da0486f87..95fda41240 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -350,7 +350,7 @@ module.exports = function(app) { user => { if (!user) { req.flash('errors', { - msg: `We couldn't find the user with the username ${username}` + msg: `We couldn't find a user with the username ${username}` }); return res.redirect('/'); } @@ -422,7 +422,7 @@ module.exports = function(app) { if (err) { return next(err); } user.updateAttribute('isLocked', typeof user.isLocked !== "undefined" ? !user.isLocked : true, function(err) { if (err) { return next(err); } - req.flash('info', { msg: 'Privacy preferences updated successfully.' }); + req.flash('info', { msg: 'We\'ve successfully updated your Privacy preferences.' }); res.redirect('/settings'); }); }); @@ -433,7 +433,7 @@ module.exports = function(app) { 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.' }); + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); res.redirect('/settings'); }); }); @@ -444,7 +444,7 @@ module.exports = function(app) { 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.' }); + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); res.redirect('/settings'); }); }); @@ -455,7 +455,7 @@ module.exports = function(app) { 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.' }); + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); res.redirect('/settings'); }); }); @@ -465,7 +465,7 @@ module.exports = function(app) { User.destroyById(req.user.id, function(err) { if (err) { return next(err); } req.logout(); - req.flash('info', { msg: 'Your account has been deleted.' }); + req.flash('info', { msg: 'You\'ve successfully deleted your account.' }); return res.redirect('/'); }); } @@ -496,7 +496,7 @@ module.exports = function(app) { if (err) { return next(err); } debug('password reset processed successfully'); - req.flash('info', { msg: 'password reset processed successfully' }); + req.flash('info', { msg: 'You\'ve successfully reset your password.' }); return res.redirect('/'); }); }); From cdc44e4b7e0b2d9cb3d7a1655d237279aa43a702 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Mon, 14 Mar 2016 23:57:04 -0700 Subject: [PATCH 5/7] update unsubscribe paths --- server/boot/randomAPIs.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/server/boot/randomAPIs.js b/server/boot/randomAPIs.js index f7237bf038..6a1a646a70 100644 --- a/server/boot/randomAPIs.js +++ b/server/boot/randomAPIs.js @@ -26,7 +26,9 @@ module.exports = function(app) { router.get('/pmi-acp-agile-project-managers-form', agileProjectManagersForm); router.get('/nonprofits', nonprofits); router.get('/nonprofits-form', nonprofitsForm); - router.get('/unsubscribe/:email', unsubscribe); + router.get('/unsubscribe/:email', unsubscribeMonthly); + router.get('/unsubscribe-notifications/:email', unsubscribeNotifications); + router.get('/unsubscribe-quincy/:email', unsubscribeQuincy); router.get('/unsubscribed', unsubscribed); router.get('/get-started', getStarted); router.get('/submit-cat-photo', submitCatPhoto); @@ -279,18 +281,33 @@ module.exports = function(app) { res.redirect('https://twitch.tv/freecodecamp'); } - function unsubscribe(req, res, next) { + function unsubscribeMonthly(req, res, next) { User.findOne({ where: { email: req.params.email } }, function(err, user) { - if (user) { + user.updateAttribute('sendMonthlyEmail', false, function(err) { if (err) { return next(err); } - user.sendMonthlyEmail = false; - return user.save(function() { - if (err) { return next(err); } - return res.redirect('/unsubscribed'); - }); - } else { - return res.redirect('/unsubscribed'); - } + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); + res.redirect('/unsubscribed'); + }); + }); + } + + function unsubscribeNotifications(req, res, next) { + User.findOne({ where: { email: req.params.email } }, function(err, user) { + user.updateAttribute('sendNotificationEmail', false, function(err) { + if (err) { return next(err); } + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); + res.redirect('/unsubscribed'); + }); + }); + } + + function unsubscribeQuincy(req, res, next) { + User.findOne({ where: { email: req.params.email } }, function(err, user) { + user.updateAttribute('sendQuincyEmail', false, function(err) { + if (err) { return next(err); } + req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); + res.redirect('/unsubscribed'); + }); }); } From 891c0c2e5a10dbda8dd75d5170b883360f68defd Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Tue, 15 Mar 2016 00:00:53 -0700 Subject: [PATCH 6/7] remove trailing whitespace --- server/boot/randomAPIs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/boot/randomAPIs.js b/server/boot/randomAPIs.js index 6a1a646a70..34adb26487 100644 --- a/server/boot/randomAPIs.js +++ b/server/boot/randomAPIs.js @@ -28,7 +28,7 @@ module.exports = function(app) { router.get('/nonprofits-form', nonprofitsForm); router.get('/unsubscribe/:email', unsubscribeMonthly); router.get('/unsubscribe-notifications/:email', unsubscribeNotifications); - router.get('/unsubscribe-quincy/:email', unsubscribeQuincy); + router.get('/unsubscribe-quincy/:email', unsubscribeQuincy); router.get('/unsubscribed', unsubscribed); router.get('/get-started', getStarted); router.get('/submit-cat-photo', submitCatPhoto); From ee6ca2c5ae7fd533182d663acc76fc37348e1875 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Tue, 15 Mar 2016 11:22:54 -0700 Subject: [PATCH 7/7] address eslint errors from refactor --- server/boot/randomAPIs.js | 36 ++++++++++++++++++--------- server/boot/user.js | 52 +++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/server/boot/randomAPIs.js b/server/boot/randomAPIs.js index 34adb26487..d9ef88f7ba 100644 --- a/server/boot/randomAPIs.js +++ b/server/boot/randomAPIs.js @@ -282,31 +282,43 @@ module.exports = function(app) { } function unsubscribeMonthly(req, res, next) { - User.findOne({ where: { email: req.params.email } }, function(err, user) { - user.updateAttribute('sendMonthlyEmail', false, function(err) { + req.checkParams('email', 'Must send a valid email').isEmail(); + return User.findOne({ where: { email: req.params.email } }, (err, user) => { + if (err) { return next(err); } + return user.updateAttribute('sendMonthlyEmail', false, (err) => { if (err) { return next(err); } - req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/unsubscribed'); + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return res.redirect('/unsubscribed'); }); }); } function unsubscribeNotifications(req, res, next) { - User.findOne({ where: { email: req.params.email } }, function(err, user) { - user.updateAttribute('sendNotificationEmail', false, function(err) { + req.checkParams('email', 'Must send a valid email').isEmail(); + return User.findOne({ where: { email: req.params.email } }, (err, user) => { + if (err) { return next(err); } + return user.updateAttribute('sendNotificationEmail', false, (err) => { if (err) { return next(err); } - req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/unsubscribed'); + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return res.redirect('/unsubscribed'); }); }); } function unsubscribeQuincy(req, res, next) { - User.findOne({ where: { email: req.params.email } }, function(err, user) { - user.updateAttribute('sendQuincyEmail', false, function(err) { + req.checkParams('email', 'Must send a valid email').isEmail(); + return User.findOne({ where: { email: req.params.email } }, (err, user) => { + if (err) { return next(err); } + return user.updateAttribute('sendQuincyEmail', false, (err) => { if (err) { return next(err); } - req.flash('info', { msg: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/unsubscribed'); + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return res.redirect('/unsubscribed'); }); }); } diff --git a/server/boot/user.js b/server/boot/user.js index 95fda41240..fc3986d54c 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -248,7 +248,7 @@ module.exports = function(app) { return res.redirect('/' + username); } - function getSettings(req, res, next) { + function getSettings(req, res) { res.render('account/settings'); } @@ -420,10 +420,12 @@ module.exports = function(app) { function toggleLockdownMode(req, res, next) { return User.findById(req.accessToken.userId, function(err, user) { if (err) { return next(err); } - user.updateAttribute('isLocked', typeof user.isLocked !== "undefined" ? !user.isLocked : true, function(err) { + return user.updateAttribute('isLocked', !user.isLocked, function(err) { if (err) { return next(err); } - req.flash('info', { msg: 'We\'ve successfully updated your Privacy preferences.' }); - res.redirect('/settings'); + req.flash('info', { + msg: 'We\'ve successfully updated your Privacy preferences.' + }); + return res.redirect('/settings'); }); }); } @@ -431,32 +433,46 @@ module.exports = function(app) { 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: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/settings'); - }); + return user.updateAttribute( + 'sendMonthlyEmail', + !user.sendMonthlyEmail, + (err) => { + if (err) { return next(err); } + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return 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: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/settings'); - }); + return user.updateAttribute('sendQuincyEmail', !user.sendQuincyEmail, + (err) => { + if (err) { return next(err); } + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return 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: 'We\'ve successfully updated your Email preferences.' }); - res.redirect('/settings'); + return user.updateAttribute( + 'sendNotificationEmail', + !user.sendNotificationEmail, + function(err) { + if (err) { return next(err); } + req.flash('info', { + msg: 'We\'ve successfully updated your Email preferences.' + }); + return res.redirect('/settings'); }); }); }