fix(app): Normalize flash type

Changed flash messages to use types provided by Bootstrap

Closes #16395
This commit is contained in:
cassidypignatello
2018-01-08 17:25:45 -05:00
parent 3d86eaecbc
commit f158183039
8 changed files with 24 additions and 24 deletions

View File

@ -238,7 +238,7 @@ module.exports = function(User) {
return User.findById(uid, (err, user) => { return User.findById(uid, (err, user) => {
if (err || !user || !user.newEmail) { if (err || !user || !user.newEmail) {
ctx.req.flash('error', { ctx.req.flash('danger', {
msg: dedent`Oops, something went wrong, please try again later` msg: dedent`Oops, something went wrong, please try again later`
}); });
return ctx.res.redirect('/'); return ctx.res.redirect('/');
@ -309,7 +309,7 @@ module.exports = function(User) {
return next(); return next();
} }
req.flash('error', { req.flash('danger', {
msg: dedent` msg: dedent`
The ${req.body.email} email address is already associated with an account. The ${req.body.email} email address is already associated with an account.
Try signing in with it here instead. Try signing in with it here instead.
@ -320,7 +320,7 @@ module.exports = function(User) {
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
req.flash('error', { req.flash('danger', {
msg: 'Oops, something went wrong, please try again later' msg: 'Oops, something went wrong, please try again later'
}); });
return res.redirect('/email-signin'); return res.redirect('/email-signin');
@ -376,7 +376,7 @@ module.exports = function(User) {
var res = ctx.res; var res = ctx.res;
var req = ctx.req; var req = ctx.req;
req.flash('errors', { req.flash('danger', {
msg: 'Invalid username or password.' msg: 'Invalid username or password.'
}); });
return res.redirect('/email-signin'); return res.redirect('/email-signin');

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

@ -424,7 +424,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);
@ -433,14 +433,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);
@ -458,7 +458,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);
@ -538,7 +538,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
@ -597,13 +597,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.
@ -617,7 +617,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
@ -627,7 +627,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.
` `
@ -649,7 +649,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');
@ -714,7 +714,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

@ -30,7 +30,7 @@ export default function prodErrorHandler() {
if (type === 'html') { if (type === 'html') {
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.negative-30 .row.flashMessage.negative-30
.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')