mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #12227, fix crash in redirect
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const user = require('../user');
|
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
|
|
||||||
@@ -27,17 +26,5 @@ async function doBuildHeader(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await plugins.hooks.fire('filter:middleware.buildHeader', { req: req, locals: res.locals });
|
await plugins.hooks.fire('filter:middleware.buildHeader', { req: req, locals: res.locals });
|
||||||
const [config, canLoginIfBanned] = await Promise.all([
|
res.locals.config = await controllers.api.loadConfig(req);
|
||||||
controllers.api.loadConfig(req),
|
|
||||||
user.bans.canLoginIfBanned(req.uid),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!canLoginIfBanned && req.loggedIn) {
|
|
||||||
req.logout(() => {
|
|
||||||
res.redirect('/');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.locals.config = config;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,20 @@ module.exports = function (middleware) {
|
|||||||
controllers.helpers.redirect(res, path);
|
controllers.helpers.redirect(res, path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
middleware.redirectToHomeIfBanned = helpers.try(async (req, res, next) => {
|
||||||
|
if (req.loggedIn) {
|
||||||
|
const canLoginIfBanned = await user.bans.canLoginIfBanned(req.uid);
|
||||||
|
if (!canLoginIfBanned) {
|
||||||
|
req.logout(() => {
|
||||||
|
res.redirect('/');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
middleware.requireUser = function (req, res, next) {
|
middleware.requireUser = function (req, res, next) {
|
||||||
if (req.loggedIn) {
|
if (req.loggedIn) {
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ helpers.setupPageRoute = function (...args) {
|
|||||||
middlewares = [
|
middlewares = [
|
||||||
middleware.applyBlacklist,
|
middleware.applyBlacklist,
|
||||||
middleware.authenticateRequest,
|
middleware.authenticateRequest,
|
||||||
|
middleware.redirectToHomeIfBanned,
|
||||||
middleware.maintenanceMode,
|
middleware.maintenanceMode,
|
||||||
middleware.registrationComplete,
|
middleware.registrationComplete,
|
||||||
middleware.pluginHooks,
|
middleware.pluginHooks,
|
||||||
|
|||||||
Reference in New Issue
Block a user