fix: check is banned in buildHeader

remove unused banReason
remove generateHeader function
v1.18.x
Barış Soner Uşaklı 4 years ago
parent 69f4d5ac7d
commit 4b63f9937c

@ -31,17 +31,23 @@ const relative_path = nconf.get('relative_path');
middleware.buildHeader = helpers.try(async function buildHeader(req, res, next) { middleware.buildHeader = helpers.try(async function buildHeader(req, res, next) {
res.locals.renderHeader = true; res.locals.renderHeader = true;
res.locals.isAPI = false; res.locals.isAPI = false;
const [config] = await Promise.all([ const [config, isBanned] = await Promise.all([
controllers.api.loadConfig(req), controllers.api.loadConfig(req),
user.bans.isBanned(req.uid),
plugins.fireHook('filter:middleware.buildHeader', { req: req, locals: res.locals }), plugins.fireHook('filter:middleware.buildHeader', { req: req, locals: res.locals }),
]); ]);
if (isBanned) {
req.logout();
return res.redirect('/');
}
res.locals.config = config; res.locals.config = config;
next(); next();
}); });
middleware.buildHeaderAsync = util.promisify(middleware.buildHeader); 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'; var registrationType = meta.config.registrationType || 'normal';
res.locals.config = res.locals.config || {}; res.locals.config = res.locals.config || {};
var templateValues = { var templateValues = {
@ -73,19 +79,11 @@ async function generateHeader(req, res, data) {
timeagoCode: languages.userTimeagoCode(res.locals.config.userLang), timeagoCode: languages.userTimeagoCode(res.locals.config.userLang),
browserTitle: translator.translate(controllers.helpers.buildTitle(translator.unescape(data.title))), browserTitle: translator.translate(controllers.helpers.buildTitle(translator.unescape(data.title))),
navigation: navigation.get(req.uid), navigation: navigation.get(req.uid),
banned: user.bans.isBanned(req.uid),
banReason: user.bans.getReason(req.uid),
unreadData: topics.getUnreadData({ uid: req.uid }), unreadData: topics.getUnreadData({ uid: req.uid }),
unreadChatCount: messaging.getUnreadCount(req.uid), unreadChatCount: messaging.getUnreadCount(req.uid),
unreadNotificationCount: user.notifications.getUnreadCount(req.uid), unreadNotificationCount: user.notifications.getUnreadCount(req.uid),
}); });
if (results.banned) {
req.logout();
return res.redirect('/');
}
const unreadData = { const unreadData = {
'': {}, '': {},
new: {}, new: {},
@ -179,11 +177,7 @@ async function generateHeader(req, res, data) {
data: data, data: data,
}); });
return hookReturn.templateValues; return await req.app.renderAsync('header', hookReturn.templateValues);
}
middleware.renderHeader = async function renderHeader(req, res, data) {
return await req.app.renderAsync('header', await generateHeader(req, res, data));
}; };
middleware.renderFooter = async function renderFooter(req, res, templateValues) { middleware.renderFooter = async function renderFooter(req, res, templateValues) {

Loading…
Cancel
Save