Show flash message on every page when cheater is logged in

This commit is contained in:
Arsen Melikyan
2016-07-27 19:40:20 +04:00
parent 0520a7b3c9
commit 510ce1fe83
3 changed files with 32 additions and 2 deletions

View File

@ -336,7 +336,7 @@ module.exports = function(app) {
return data;
}, {});
if (userPortfolio.isCheater) {
if (userPortfolio.isCheater && !user) {
req.flash('errors', {
msg: dedent`
Upon review, this account has been flagged for academic

View File

@ -49,7 +49,8 @@
"./middlewares/jade-helpers": {},
"./middlewares/global-locals": {},
"./middlewares/revision-helpers": {},
"./middlewares/migrate-completed-challenges": {}
"./middlewares/migrate-completed-challenges": {},
"./middlewares/flash-cheaters": {}
},
"routes": {
},

View File

@ -0,0 +1,29 @@
import dedent from 'dedent';
const ALLOWED_METHODS = ['GET'];
const EXCLUDED_PATHS = [
'/api/flyers/findOne',
'/challenges/current-challenge',
'/challenges/next-challenge',
'/map-aside',
'/signout'
];
export default function flashCheaters() {
return function(req, res, next) {
if (
ALLOWED_METHODS.indexOf(req.method) !== -1 &&
EXCLUDED_PATHS.indexOf(req.path) === -1 &&
req.user && req.url !== '/' && req.user.isCheater
) {
req.flash('errors', {
msg: dedent`
Upon review, this account has been flagged for academic
dishonesty. If youre the owner of this account contact
team@freecodecamp.com for details.
`
});
}
return next();
};
}