Merge pull request #16447 from cassidypignatello/fix/normalize-flash-type

fix(app): Normalize flash type
This commit is contained in:
Berkeley Martinez
2018-01-10 15:15:25 -08:00
committed by GitHub
7 changed files with 20 additions and 20 deletions

View File

@ -261,7 +261,7 @@ export default function(app) {
!completedChallenge.githubLink !completedChallenge.githubLink
) )
) { ) {
req.flash('errors', { req.flash('danger', {
msg: 'You haven\'t supplied the necessary URLs for us to inspect ' + msg: 'You haven\'t supplied the necessary URLs for us to inspect ' +
'your work.' 'your work.'
}); });

View File

@ -281,7 +281,7 @@ module.exports = function(app) {
let social = req.params.social; let social = req.params.social;
if (!social) { if (!social) {
req.flash('errors', { req.flash('danger', {
msg: 'No social account found' msg: 'No social account found'
}); });
return res.redirect('/' + username); return res.redirect('/' + username);
@ -290,14 +290,14 @@ module.exports = function(app) {
social = social.toLowerCase(); social = social.toLowerCase();
const validSocialAccounts = ['twitter', 'linkedin']; const validSocialAccounts = ['twitter', 'linkedin'];
if (validSocialAccounts.indexOf(social) === -1) { if (validSocialAccounts.indexOf(social) === -1) {
req.flash('errors', { req.flash('danger', {
msg: 'Invalid social account' msg: 'Invalid social account'
}); });
return res.redirect('/' + username); return res.redirect('/' + username);
} }
if (!user[social]) { if (!user[social]) {
req.flash('errors', { req.flash('danger', {
msg: `No ${social} account associated` msg: `No ${social} account associated`
}); });
return res.redirect('/' + username); return res.redirect('/' + username);
@ -315,7 +315,7 @@ module.exports = function(app) {
// assumed user identity is unique by provider // assumed user identity is unique by provider
let identity = identities.shift(); let identity = identities.shift();
if (!identity) { if (!identity) {
req.flash('errors', { req.flash('danger', {
msg: 'No social account found' msg: 'No social account found'
}); });
return res.redirect('/' + username); return res.redirect('/' + username);
@ -395,7 +395,7 @@ module.exports = function(app) {
}, {}); }, {});
if (userPortfolio.isCheater && !user) { if (userPortfolio.isCheater && !user) {
req.flash('errors', { req.flash('danger', {
msg: dedent` msg: dedent`
Upon review, this account has been flagged for academic Upon review, this account has been flagged for academic
dishonesty. If youre the owner of this account contact dishonesty. If youre the owner of this account contact
@ -459,13 +459,13 @@ module.exports = function(app) {
.subscribe( .subscribe(
user => { user => {
if (!user) { if (!user) {
req.flash('errors', { req.flash('danger', {
msg: `We couldn't find a user with the username ${username}` msg: `We couldn't find a user with the username ${username}`
}); });
return res.redirect('/'); return res.redirect('/');
} }
if (!user.isGithubCool) { if (!user.isGithubCool) {
req.flash('errors', { req.flash('danger', {
msg: dedent` msg: dedent`
This user needs to link GitHub with their account This user needs to link GitHub with their account
in order for others to be able to view their certificate. in order for others to be able to view their certificate.
@ -479,7 +479,7 @@ module.exports = function(app) {
} }
if (user.isLocked) { if (user.isLocked) {
req.flash('errors', { req.flash('danger', {
msg: dedent` msg: dedent`
${username} has chosen to make their profile ${username} has chosen to make their profile
private. They will need to make their profile public private. They will need to make their profile public
@ -489,7 +489,7 @@ module.exports = function(app) {
return res.redirect('back'); return res.redirect('back');
} }
if (!user.isHonest) { if (!user.isHonest) {
req.flash('errors', { req.flash('danger', {
msg: dedent` msg: dedent`
${username} has not yet agreed to our Academic Honesty Pledge. ${username} has not yet agreed to our Academic Honesty Pledge.
` `
@ -511,7 +511,7 @@ module.exports = function(app) {
} }
); );
} }
req.flash('errors', { req.flash('danger', {
msg: `Looks like user ${username} is not ${certText[certType]}` msg: `Looks like user ${username} is not ${certText[certType]}`
}); });
return res.redirect('back'); return res.redirect('back');
@ -576,7 +576,7 @@ module.exports = function(app) {
const report = req.sanitize('reportDescription').trimTags(); const report = req.sanitize('reportDescription').trimTags();
if (!username || !report || report === '') { if (!username || !report || report === '') {
req.flash('errors', { req.flash('danger', {
msg: 'Oops, something is not right please re-check your submission.' msg: 'Oops, something is not right please re-check your submission.'
}); });
return next(); return next();

View File

@ -23,7 +23,7 @@ export default function redirectLang(app) {
} }
if (type === 'html') { if (type === 'html') {
req.flash('errors', { req.flash('danger', {
msg: `We couldn't find path ${ path }` msg: `We couldn't find path ${ path }`
}); });
return res.render('404', { title: '404'}); return res.render('404', { title: '404'});

View File

@ -80,7 +80,7 @@ export default function prodErrorHandler() {
} }
if (typeof req.flash === 'function') { if (typeof req.flash === 'function') {
req.flash( req.flash(
handled.type || 'errors', handled.type || 'danger',
{ msg: message } { msg: message }
); );
} }

View File

@ -16,7 +16,7 @@ export default function flashCheaters() {
EXCLUDED_PATHS.indexOf(req.path) === -1 && EXCLUDED_PATHS.indexOf(req.path) === -1 &&
req.user && req.url !== '/' && req.user.isCheater req.user && req.url !== '/' && req.user.isCheater
) { ) {
req.flash('errors', { req.flash('danger', {
msg: dedent` msg: dedent`
Upon review, this account has been flagged for academic Upon review, this account has been flagged for academic
dishonesty. If youre the owner of this account contact dishonesty. If youre the owner of this account contact

View File

@ -1,4 +1,4 @@
export function ifNoUserRedirectTo(url, message, type = 'errors') { export function ifNoUserRedirectTo(url, message, type = 'danger') {
return function(req, res, next) { return function(req, res, next) {
const { path } = req; const { path } = req;
if (req.user) { if (req.user) {
@ -35,7 +35,7 @@ export function ifNotVerifiedRedirectToSettings(req, res, next) {
return next(); return next();
} }
if (!user.emailVerified) { if (!user.emailVerified) {
req.flash('error', { req.flash('danger', {
msg: 'We do not have your verified email address on record, ' msg: 'We do not have your verified email address on record, '
+ 'please add it in the settings to continue with your request.' + 'please add it in the settings to continue with your request.'
}); });

View File

@ -1,12 +1,12 @@
.container .container
.row.flashMessage .row.flashMessage
.col-xs-12.col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3 .col-xs-12.col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3
if (messages.errors || messages.error) if (messages.danger)
.alert.alert-danger.fade.in .alert.alert-danger.fade.in
button.close(type='button', data-dismiss='alert') button.close(type='button', data-dismiss='alert')
span.ion-close-circled span.ion-close-circled
for error in (messages.errors || messages.error) for danger in (messages.danger)
div!= error.msg || error div!= danger.msg || danger
if messages.info if messages.info
.alert.alert-info.fade.in .alert.alert-info.fade.in
button.close(type='button', data-dismiss='alert') button.close(type='button', data-dismiss='alert')