Files
freeCodeCamp/server/utils/middleware.js
Mrugesh Mohapatra 1f67c72fc6 feat(user): Report profiles
This adds a simple email-based mechanism to report profiles for
abuse. An email with text from the report is sent to Free Code
Camp's support account with the reporter's account in copy. This
also adds the reporter's details to the report for follow ups.
2017-01-13 00:14:29 +05:30

46 lines
998 B
JavaScript

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}`
});
return res.redirect(url);
};
}
export function ifNoUserSend(sendThis) {
return function(req, res, next) {
if (req.user) {
return next();
}
return res.status(200).send(sendThis);
};
}
export function ifNoUser401(req, res, next) {
if (req.user) {
return next();
}
return res.status(401).end();
}
export function ifNotVerifiedRedirectToSettings(req, res, next) {
const { user } = req;
if (!user) {
return next();
}
if (!user.emailVerified) {
req.flash('error', {
msg: '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();
}