diff --git a/server/boot/authentication.js b/server/boot/authentication.js index ded7047e18..37bfbd3d6e 100644 --- a/server/boot/authentication.js +++ b/server/boot/authentication.js @@ -171,9 +171,10 @@ module.exports = function enableAuthentication(app) { redirectTo = req.session.returnTo; } - req.flash('success', { msg: + req.flash( + 'success', 'Success! You have signed in to your account. Happy Coding!' - }); + ); return res.redirect(redirectTo); }) diff --git a/server/boot/challenge.js b/server/boot/challenge.js index eeeb2a8fbc..57ec2410fa 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -261,10 +261,10 @@ export default function(app) { !completedChallenge.githubLink ) ) { - req.flash('danger', { - msg: 'You haven\'t supplied the necessary URLs for us to inspect ' + - 'your work.' - }); + req.flash( + 'danger', + 'You haven\'t supplied the necessary URLs for us to inspect your work.' + ); return res.sendStatus(403); } diff --git a/server/boot/commit.js b/server/boot/commit.js index e4990ed50c..734a5b9019 100644 --- a/server/boot/commit.js +++ b/server/boot/commit.js @@ -103,14 +103,15 @@ export default function commit(app) { pledge => { if (pledge) { debug('found previous pledge'); - req.flash('info', { - msg: dedent` + req.flash( + 'info', + dedent` Looks like you already have a pledge to ${pledge.displayName}. Clicking "Commit" here will replace your old commitment. If you do change your commitment, please remember to cancel your previous recurring donation directly with ${pledge.displayName}. ` - }); + ); } res.render( 'commit/', @@ -165,14 +166,15 @@ export default function commit(app) { }) .subscribe( ({ displayName, goal, amount }) => { - req.flash('success', { - msg: dedent` + req.flash( + 'success', + dedent` Congratulations, you have committed to giving ${displayName} $${amount} each month until you have completed your ${goal}. Please remember to cancel your pledge directly with ${displayName} once you finish. ` - }); + ); res.redirect('/' + user.username); }, next @@ -229,7 +231,7 @@ export default function commit(app) { there's no pledge to stop. `; } - req.flash('info', { msg }); + req.flash('info', msg); return res.redirect(`/${user.username}`); }, next diff --git a/server/boot/randomAPIs.js b/server/boot/randomAPIs.js index d81ee72e19..4763dc74b2 100644 --- a/server/boot/randomAPIs.js +++ b/server/boot/randomAPIs.js @@ -134,15 +134,17 @@ module.exports = function(app) { return User.updateAll(query, params, function(err, info) { if (err) { return next(err); } if (info.count === 0) { - req.flash('info', { - msg: 'Email address not found. ' + - 'Please update your Email preferences from your profile.' - }); + req.flash( + 'info', + 'Email address not found. ' + + 'Please update your Email preferences from your profile.' + ); return res.redirect('/map'); } else { - req.flash('info', { - msg: 'We\'ve successfully updated your Email preferences.' - }); + req.flash( + 'info', + 'We\'ve successfully updated your Email preferences.' + ); return res.redirect('/unsubscribed'); } }); diff --git a/server/boot/user.js b/server/boot/user.js index 5e735f796b..5df361b91c 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -266,25 +266,19 @@ module.exports = function(app) { let social = req.params.social; if (!social) { - req.flash('danger', { - msg: 'No social account found' - }); + req.flash('danger', 'No social account found'); return res.redirect('/' + username); } social = social.toLowerCase(); const validSocialAccounts = ['twitter', 'linkedin']; if (validSocialAccounts.indexOf(social) === -1) { - req.flash('danger', { - msg: 'Invalid social account' - }); + req.flash('danger', 'Invalid social account'); return res.redirect('/' + username); } if (!user[social]) { - req.flash('danger', { - msg: `No ${social} account associated` - }); + req.flash('danger', `No ${social} account associated`); return res.redirect('/' + username); } @@ -300,9 +294,7 @@ module.exports = function(app) { // assumed user identity is unique by provider let identity = identities.shift(); if (!identity) { - req.flash('danger', { - msg: 'No social account found' - }); + req.flash('danger', 'No social account found'); return res.redirect('/' + username); } @@ -315,9 +307,7 @@ module.exports = function(app) { .subscribe(() => { debug(`${social} has been unlinked successfully`); - req.flash('info', { - msg: `You\'ve successfully unlinked your ${social}.` - }); + req.flash('info', `You've successfully unlinked your ${social}.`); return res.redirect('/' + username); }, next); }); @@ -380,13 +370,14 @@ module.exports = function(app) { }, {}); if (userPortfolio.isCheater && !user) { - req.flash('danger', { - msg: dedent` + req.flash( + 'danger', + dedent` Upon review, this account has been flagged for academic dishonesty. If you’re the owner of this account contact team@freecodecamp.org for details. ` - }); + ); } if (userPortfolio.bio) { @@ -444,18 +435,20 @@ module.exports = function(app) { .subscribe( user => { if (!user) { - req.flash('danger', { - msg: `We couldn't find a user with the username ${username}` - }); + req.flash( + 'danger', + `We couldn't find a user with the username ${username}` + ); return res.redirect('/'); } if (!user.isGithubCool) { - req.flash('danger', { - msg: dedent` + req.flash( + 'danger', + dedent` This user needs to link GitHub with their account in order for others to be able to view their certificate. ` - }); + ); return res.redirect('back'); } @@ -464,21 +457,23 @@ module.exports = function(app) { } if (user.isLocked) { - req.flash('danger', { - msg: dedent` + req.flash( + 'danger', + dedent` ${username} has chosen to make their profile private. They will need to make their profile public in order for others to be able to view their certificate. ` - }); + ); return res.redirect('back'); } if (!user.isHonest) { - req.flash('danger', { - msg: dedent` + req.flash( + 'danger', + dedent` ${username} has not yet agreed to our Academic Honesty Pledge. ` - }); + ); return res.redirect('back'); } @@ -496,9 +491,10 @@ module.exports = function(app) { } ); } - req.flash('danger', { - msg: `Looks like user ${username} is not ${certText[certType]}` - }); + req.flash( + 'danger', + `Looks like user ${username} is not ${certText[certType]}` + ); return res.redirect('back'); }, next @@ -513,7 +509,7 @@ module.exports = function(app) { User.destroyById(req.user.id, function(err) { if (err) { return next(err); } req.logout(); - req.flash('info', { msg: 'You\'ve successfully deleted your account.' }); + req.flash('info', 'You\'ve successfully deleted your account.'); return res.redirect('/'); }); } @@ -541,7 +537,7 @@ module.exports = function(app) { challegesCompleted: [] }, function(err) { if (err) { return next(err); } - req.flash('info', { msg: 'You\'ve successfully reset your progress.' }); + req.flash('info', 'You\'ve successfully reset your progress.'); return res.redirect('/'); }); }); @@ -561,9 +557,10 @@ module.exports = function(app) { const report = req.sanitize('reportDescription').trimTags(); if (!username || !report || report === '') { - req.flash('danger', { - msg: 'Oops, something is not right please re-check your submission.' - }); + req.flash( + 'danger', + 'Oops, something is not right please re-check your submission.' + ); return next(); } @@ -591,9 +588,10 @@ module.exports = function(app) { return next(err); } - req.flash('info', { - msg: 'A report was sent to the team with ' + user.email + ' in copy.' - }); + req.flash( + 'info', + `A report was sent to the team with ${user.email} in copy.` + ); return res.redirect('/'); }); } diff --git a/server/boot/z-lang-redirect.js b/server/boot/z-lang-redirect.js index 5c3006cf55..64be437951 100644 --- a/server/boot/z-lang-redirect.js +++ b/server/boot/z-lang-redirect.js @@ -23,9 +23,7 @@ export default function redirectLang(app) { } if (type === 'html') { - req.flash('danger', { - msg: `We couldn't find path ${ path }` - }); + req.flash('danger', `We couldn't find path ${ path }`); return res.render('404', { title: '404'}); } diff --git a/server/middlewares/error-handlers.js b/server/middlewares/error-handlers.js index 45cecbb090..59519db5b8 100644 --- a/server/middlewares/error-handlers.js +++ b/server/middlewares/error-handlers.js @@ -79,10 +79,7 @@ export default function prodErrorHandler() { ); } if (typeof req.flash === 'function') { - req.flash( - handled.type || 'danger', - { msg: message } - ); + req.flash(handled.type || 'danger', message); } return res.redirect(redirectTo); // json diff --git a/server/middlewares/flash-cheaters.js b/server/middlewares/flash-cheaters.js index 9c38d70b89..cb76259c95 100644 --- a/server/middlewares/flash-cheaters.js +++ b/server/middlewares/flash-cheaters.js @@ -16,13 +16,14 @@ export default function flashCheaters() { EXCLUDED_PATHS.indexOf(req.path) === -1 && req.user && req.url !== '/' && req.user.isCheater ) { - req.flash('danger', { - msg: dedent` + req.flash( + 'danger', + dedent` Upon review, this account has been flagged for academic dishonesty. If you’re the owner of this account contact team@freecodecamp.org for details. ` - }); + ); } return next(); }; diff --git a/server/utils/middleware.js b/server/utils/middleware.js index 3df00254c8..1aa455a0fb 100644 --- a/server/utils/middleware.js +++ b/server/utils/middleware.js @@ -1,13 +1,13 @@ -export function ifNoUserRedirectTo(url, message, type = 'danger') { +import dedent from 'dedent'; + +export function ifNoUserRedirectTo(url, message, type = 'errors') { return function(req, res, next) { const { path } = req; if (req.user) { return next(); } - req.flash(type, { - msg: message || `You must be signed in to access ${path}` - }); + req.flash(type, message || `You must be signed in to access ${path}`); return res.redirect(url); }; @@ -35,10 +35,13 @@ export function ifNotVerifiedRedirectToSettings(req, res, next) { return next(); } if (!user.emailVerified) { - req.flash('danger', { - msg: 'We do not have your verified email address on record, ' - + 'please add it in the settings to continue with your request.' - }); + req.flash( + 'danger', + dedent` + We do not have your verified email address on record, + please add it in the settings to continue with your request. + ` + ); return res.redirect('/settings'); } return next(); diff --git a/server/views/partials/flash.jade b/server/views/partials/flash.jade index 07bef1667f..1f83d79c07 100644 --- a/server/views/partials/flash.jade +++ b/server/views/partials/flash.jade @@ -1,21 +1,21 @@ .container .row.flashMessage .col-xs-12.col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3 - if (messages.danger) + if messages.danger .alert.alert-danger.fade.in button.close(type='button', data-dismiss='alert') span.ion-close-circled - for danger in (messages.danger) - div!= danger.msg || danger + for msg in messages.danger + div!= msg if messages.info .alert.alert-info.fade.in button.close(type='button', data-dismiss='alert') span.ion-close-circled - for info in messages.info - div!= info.msg + for msg in messages.info + div!= msg if messages.success .alert.alert-success.fade.in button.close(type='button', data-dismiss='alert') span.ion-close-circled - for success in messages.success - div!= success.msg + for msg in messages.success + div!= msg