fix(server/flash): Api to match documentation
This fixes duplication issues and normalize our use with everyone else
This commit is contained in:
@ -171,9 +171,10 @@ module.exports = function enableAuthentication(app) {
|
|||||||
redirectTo = req.session.returnTo;
|
redirectTo = req.session.returnTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.flash('success', { msg:
|
req.flash(
|
||||||
|
'success',
|
||||||
'Success! You have signed in to your account. Happy Coding!'
|
'Success! You have signed in to your account. Happy Coding!'
|
||||||
});
|
);
|
||||||
|
|
||||||
return res.redirect(redirectTo);
|
return res.redirect(redirectTo);
|
||||||
})
|
})
|
||||||
|
@ -261,10 +261,10 @@ export default function(app) {
|
|||||||
!completedChallenge.githubLink
|
!completedChallenge.githubLink
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: 'You haven\'t supplied the necessary URLs for us to inspect ' +
|
'danger',
|
||||||
'your work.'
|
'You haven\'t supplied the necessary URLs for us to inspect your work.'
|
||||||
});
|
);
|
||||||
return res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,14 +103,15 @@ export default function commit(app) {
|
|||||||
pledge => {
|
pledge => {
|
||||||
if (pledge) {
|
if (pledge) {
|
||||||
debug('found previous pledge');
|
debug('found previous pledge');
|
||||||
req.flash('info', {
|
req.flash(
|
||||||
msg: dedent`
|
'info',
|
||||||
|
dedent`
|
||||||
Looks like you already have a pledge to ${pledge.displayName}.
|
Looks like you already have a pledge to ${pledge.displayName}.
|
||||||
Clicking "Commit" here will replace your old commitment. If you
|
Clicking "Commit" here will replace your old commitment. If you
|
||||||
do change your commitment, please remember to cancel your
|
do change your commitment, please remember to cancel your
|
||||||
previous recurring donation directly with ${pledge.displayName}.
|
previous recurring donation directly with ${pledge.displayName}.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
res.render(
|
res.render(
|
||||||
'commit/',
|
'commit/',
|
||||||
@ -165,14 +166,15 @@ export default function commit(app) {
|
|||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
({ displayName, goal, amount }) => {
|
({ displayName, goal, amount }) => {
|
||||||
req.flash('success', {
|
req.flash(
|
||||||
msg: dedent`
|
'success',
|
||||||
|
dedent`
|
||||||
Congratulations, you have committed to giving
|
Congratulations, you have committed to giving
|
||||||
${displayName} $${amount} each month until you have completed
|
${displayName} $${amount} each month until you have completed
|
||||||
your ${goal}. Please remember to cancel your pledge directly
|
your ${goal}. Please remember to cancel your pledge directly
|
||||||
with ${displayName} once you finish.
|
with ${displayName} once you finish.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
res.redirect('/' + user.username);
|
res.redirect('/' + user.username);
|
||||||
},
|
},
|
||||||
next
|
next
|
||||||
@ -229,7 +231,7 @@ export default function commit(app) {
|
|||||||
there's no pledge to stop.
|
there's no pledge to stop.
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
req.flash('info', { msg });
|
req.flash('info', msg);
|
||||||
return res.redirect(`/${user.username}`);
|
return res.redirect(`/${user.username}`);
|
||||||
},
|
},
|
||||||
next
|
next
|
||||||
|
@ -134,15 +134,17 @@ module.exports = function(app) {
|
|||||||
return User.updateAll(query, params, function(err, info) {
|
return User.updateAll(query, params, function(err, info) {
|
||||||
if (err) { return next(err); }
|
if (err) { return next(err); }
|
||||||
if (info.count === 0) {
|
if (info.count === 0) {
|
||||||
req.flash('info', {
|
req.flash(
|
||||||
msg: 'Email address not found. ' +
|
'info',
|
||||||
'Please update your Email preferences from your profile.'
|
'Email address not found. ' +
|
||||||
});
|
'Please update your Email preferences from your profile.'
|
||||||
|
);
|
||||||
return res.redirect('/map');
|
return res.redirect('/map');
|
||||||
} else {
|
} else {
|
||||||
req.flash('info', {
|
req.flash(
|
||||||
msg: 'We\'ve successfully updated your Email preferences.'
|
'info',
|
||||||
});
|
'We\'ve successfully updated your Email preferences.'
|
||||||
|
);
|
||||||
return res.redirect('/unsubscribed');
|
return res.redirect('/unsubscribed');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -266,25 +266,19 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
let social = req.params.social;
|
let social = req.params.social;
|
||||||
if (!social) {
|
if (!social) {
|
||||||
req.flash('danger', {
|
req.flash('danger', 'No social account found');
|
||||||
msg: 'No social account found'
|
|
||||||
});
|
|
||||||
return res.redirect('/' + username);
|
return res.redirect('/' + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
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('danger', {
|
req.flash('danger', 'Invalid social account');
|
||||||
msg: 'Invalid social account'
|
|
||||||
});
|
|
||||||
return res.redirect('/' + username);
|
return res.redirect('/' + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user[social]) {
|
if (!user[social]) {
|
||||||
req.flash('danger', {
|
req.flash('danger', `No ${social} account associated`);
|
||||||
msg: `No ${social} account associated`
|
|
||||||
});
|
|
||||||
return res.redirect('/' + username);
|
return res.redirect('/' + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,9 +294,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('danger', {
|
req.flash('danger', 'No social account found');
|
||||||
msg: 'No social account found'
|
|
||||||
});
|
|
||||||
return res.redirect('/' + username);
|
return res.redirect('/' + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,9 +307,7 @@ module.exports = function(app) {
|
|||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
debug(`${social} has been unlinked successfully`);
|
debug(`${social} has been unlinked successfully`);
|
||||||
|
|
||||||
req.flash('info', {
|
req.flash('info', `You've successfully unlinked your ${social}.`);
|
||||||
msg: `You\'ve successfully unlinked your ${social}.`
|
|
||||||
});
|
|
||||||
return res.redirect('/' + username);
|
return res.redirect('/' + username);
|
||||||
}, next);
|
}, next);
|
||||||
});
|
});
|
||||||
@ -380,13 +370,14 @@ module.exports = function(app) {
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
if (userPortfolio.isCheater && !user) {
|
if (userPortfolio.isCheater && !user) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: dedent`
|
'danger',
|
||||||
|
dedent`
|
||||||
Upon review, this account has been flagged for academic
|
Upon review, this account has been flagged for academic
|
||||||
dishonesty. If you’re the owner of this account contact
|
dishonesty. If you’re the owner of this account contact
|
||||||
team@freecodecamp.org for details.
|
team@freecodecamp.org for details.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userPortfolio.bio) {
|
if (userPortfolio.bio) {
|
||||||
@ -444,18 +435,20 @@ module.exports = function(app) {
|
|||||||
.subscribe(
|
.subscribe(
|
||||||
user => {
|
user => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: `We couldn't find a user with the username ${username}`
|
'danger',
|
||||||
});
|
`We couldn't find a user with the username ${username}`
|
||||||
|
);
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
if (!user.isGithubCool) {
|
if (!user.isGithubCool) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: dedent`
|
'danger',
|
||||||
|
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.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
return res.redirect('back');
|
return res.redirect('back');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,21 +457,23 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.isLocked) {
|
if (user.isLocked) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: dedent`
|
'danger',
|
||||||
|
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
|
||||||
in order for others to be able to view their certificate.
|
in order for others to be able to view their certificate.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
return res.redirect('back');
|
return res.redirect('back');
|
||||||
}
|
}
|
||||||
if (!user.isHonest) {
|
if (!user.isHonest) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: dedent`
|
'danger',
|
||||||
|
dedent`
|
||||||
${username} has not yet agreed to our Academic Honesty Pledge.
|
${username} has not yet agreed to our Academic Honesty Pledge.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
return res.redirect('back');
|
return res.redirect('back');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,9 +491,10 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: `Looks like user ${username} is not ${certText[certType]}`
|
'danger',
|
||||||
});
|
`Looks like user ${username} is not ${certText[certType]}`
|
||||||
|
);
|
||||||
return res.redirect('back');
|
return res.redirect('back');
|
||||||
},
|
},
|
||||||
next
|
next
|
||||||
@ -513,7 +509,7 @@ module.exports = function(app) {
|
|||||||
User.destroyById(req.user.id, function(err) {
|
User.destroyById(req.user.id, function(err) {
|
||||||
if (err) { return next(err); }
|
if (err) { return next(err); }
|
||||||
req.logout();
|
req.logout();
|
||||||
req.flash('info', { msg: 'You\'ve successfully deleted your account.' });
|
req.flash('info', 'You\'ve successfully deleted your account.');
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -541,7 +537,7 @@ module.exports = function(app) {
|
|||||||
challegesCompleted: []
|
challegesCompleted: []
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) { return next(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('/');
|
return res.redirect('/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -561,9 +557,10 @@ 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('danger', {
|
req.flash(
|
||||||
msg: 'Oops, something is not right please re-check your submission.'
|
'danger',
|
||||||
});
|
'Oops, something is not right please re-check your submission.'
|
||||||
|
);
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,9 +588,10 @@ module.exports = function(app) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.flash('info', {
|
req.flash(
|
||||||
msg: 'A report was sent to the team with ' + user.email + ' in copy.'
|
'info',
|
||||||
});
|
`A report was sent to the team with ${user.email} in copy.`
|
||||||
|
);
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,7 @@ export default function redirectLang(app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'html') {
|
if (type === 'html') {
|
||||||
req.flash('danger', {
|
req.flash('danger', `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'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +79,7 @@ export default function prodErrorHandler() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (typeof req.flash === 'function') {
|
if (typeof req.flash === 'function') {
|
||||||
req.flash(
|
req.flash(handled.type || 'danger', message);
|
||||||
handled.type || 'danger',
|
|
||||||
{ msg: message }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return res.redirect(redirectTo);
|
return res.redirect(redirectTo);
|
||||||
// json
|
// json
|
||||||
|
@ -16,13 +16,14 @@ 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('danger', {
|
req.flash(
|
||||||
msg: dedent`
|
'danger',
|
||||||
|
dedent`
|
||||||
Upon review, this account has been flagged for academic
|
Upon review, this account has been flagged for academic
|
||||||
dishonesty. If you’re the owner of this account contact
|
dishonesty. If you’re the owner of this account contact
|
||||||
team@freecodecamp.org for details.
|
team@freecodecamp.org for details.
|
||||||
`
|
`
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
@ -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) {
|
return function(req, res, next) {
|
||||||
const { path } = req;
|
const { path } = req;
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
req.flash(type, {
|
req.flash(type, message || `You must be signed in to access ${path}`);
|
||||||
msg: message || `You must be signed in to access ${path}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.redirect(url);
|
return res.redirect(url);
|
||||||
};
|
};
|
||||||
@ -35,10 +35,13 @@ export function ifNotVerifiedRedirectToSettings(req, res, next) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
if (!user.emailVerified) {
|
if (!user.emailVerified) {
|
||||||
req.flash('danger', {
|
req.flash(
|
||||||
msg: 'We do not have your verified email address on record, '
|
'danger',
|
||||||
+ 'please add it in the settings to continue with your request.'
|
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 res.redirect('/settings');
|
||||||
}
|
}
|
||||||
return next();
|
return next();
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
.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.danger)
|
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 danger in (messages.danger)
|
for msg in messages.danger
|
||||||
div!= danger.msg || danger
|
div!= msg
|
||||||
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')
|
||||||
span.ion-close-circled
|
span.ion-close-circled
|
||||||
for info in messages.info
|
for msg in messages.info
|
||||||
div!= info.msg
|
div!= msg
|
||||||
if messages.success
|
if messages.success
|
||||||
.alert.alert-success.fade.in
|
.alert.alert-success.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 success in messages.success
|
for msg in messages.success
|
||||||
div!= success.msg
|
div!= msg
|
||||||
|
Reference in New Issue
Block a user