From 4b63f9937cd4fa162b4dbb10685c22590e90862d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 4 Nov 2020 13:23:10 -0500 Subject: [PATCH] fix: check is banned in buildHeader remove unused banReason remove generateHeader function --- src/middleware/header.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/middleware/header.js b/src/middleware/header.js index b51d5404b4..deb9cbce61 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -31,17 +31,23 @@ const relative_path = nconf.get('relative_path'); middleware.buildHeader = helpers.try(async function buildHeader(req, res, next) { res.locals.renderHeader = true; res.locals.isAPI = false; - const [config] = await Promise.all([ + const [config, isBanned] = await Promise.all([ controllers.api.loadConfig(req), + user.bans.isBanned(req.uid), plugins.fireHook('filter:middleware.buildHeader', { req: req, locals: res.locals }), ]); + + if (isBanned) { + req.logout(); + return res.redirect('/'); + } res.locals.config = config; next(); }); middleware.buildHeaderAsync = util.promisify(middleware.buildHeader); -async function generateHeader(req, res, data) { +middleware.renderHeader = async function renderHeader(req, res, data) { var registrationType = meta.config.registrationType || 'normal'; res.locals.config = res.locals.config || {}; var templateValues = { @@ -73,19 +79,11 @@ async function generateHeader(req, res, data) { timeagoCode: languages.userTimeagoCode(res.locals.config.userLang), browserTitle: translator.translate(controllers.helpers.buildTitle(translator.unescape(data.title))), navigation: navigation.get(req.uid), - banned: user.bans.isBanned(req.uid), - banReason: user.bans.getReason(req.uid), - unreadData: topics.getUnreadData({ uid: req.uid }), unreadChatCount: messaging.getUnreadCount(req.uid), unreadNotificationCount: user.notifications.getUnreadCount(req.uid), }); - if (results.banned) { - req.logout(); - return res.redirect('/'); - } - const unreadData = { '': {}, new: {}, @@ -179,11 +177,7 @@ async function generateHeader(req, res, data) { data: data, }); - return hookReturn.templateValues; -} - -middleware.renderHeader = async function renderHeader(req, res, data) { - return await req.app.renderAsync('header', await generateHeader(req, res, data)); + return await req.app.renderAsync('header', hookReturn.templateValues); }; middleware.renderFooter = async function renderFooter(req, res, templateValues) {