mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: give the rest of the middlewares names
This commit is contained in:
@@ -11,10 +11,10 @@ var widgets = require('../widgets');
|
|||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
module.exports = function (middleware) {
|
module.exports = function (middleware) {
|
||||||
middleware.processRender = function (req, res, next) {
|
middleware.processRender = function processRender(req, res, next) {
|
||||||
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
|
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
|
||||||
var render = res.render;
|
var render = res.render;
|
||||||
res.render = function (template, options, fn) {
|
res.render = function renderOverride(template, options, fn) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var req = this.req;
|
var req = this.req;
|
||||||
var defaultFn = function (err, str) {
|
var defaultFn = function (err, str) {
|
||||||
|
|||||||
@@ -43,21 +43,21 @@ module.exports = function (middleware) {
|
|||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
middleware.authenticate = function (req, res, next) {
|
middleware.authenticate = function authenticate(req, res, next) {
|
||||||
authenticate(req, res, next, function () {
|
authenticate(req, res, next, function () {
|
||||||
controllers.helpers.notAllowed(req, res, next);
|
controllers.helpers.notAllowed(req, res, next);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.authenticateOrGuest = function (req, res, next) {
|
middleware.authenticateOrGuest = function authenticateOrGuest(req, res, next) {
|
||||||
authenticate(req, res, next, next);
|
authenticate(req, res, next, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.ensureSelfOrGlobalPrivilege = function (req, res, next) {
|
middleware.ensureSelfOrGlobalPrivilege = function ensureSelfOrGlobalPrivilege(req, res, next) {
|
||||||
ensureSelfOrMethod(user.isAdminOrGlobalMod, req, res, next);
|
ensureSelfOrMethod(user.isAdminOrGlobalMod, req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.ensureSelfOrPrivileged = function (req, res, next) {
|
middleware.ensureSelfOrPrivileged = function ensureSelfOrPrivileged(req, res, next) {
|
||||||
ensureSelfOrMethod(user.isPrivileged, req, res, next);
|
ensureSelfOrMethod(user.isPrivileged, req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ module.exports = function (middleware) {
|
|||||||
], next);
|
], next);
|
||||||
}
|
}
|
||||||
|
|
||||||
middleware.checkGlobalPrivacySettings = function (req, res, next) {
|
middleware.checkGlobalPrivacySettings = function checkGlobalPrivacySettings(req, res, next) {
|
||||||
if (!req.loggedIn && meta.config.privateUserInfo) {
|
if (!req.loggedIn && meta.config.privateUserInfo) {
|
||||||
return middleware.authenticate(req, res, next);
|
return middleware.authenticate(req, res, next);
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ module.exports = function (middleware) {
|
|||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.checkAccountPermissions = function (req, res, next) {
|
middleware.checkAccountPermissions = function checkAccountPermissions(req, res, next) {
|
||||||
// This middleware ensures that only the requested user and admins can pass
|
// This middleware ensures that only the requested user and admins can pass
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -128,7 +128,7 @@ module.exports = function (middleware) {
|
|||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.redirectToAccountIfLoggedIn = function (req, res, next) {
|
middleware.redirectToAccountIfLoggedIn = function redirectToAccountIfLoggedIn(req, res, next) {
|
||||||
if (req.session.forceLogin || req.uid <= 0) {
|
if (req.session.forceLogin || req.uid <= 0) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ module.exports = function (middleware) {
|
|||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.redirectUidToUserslug = function (req, res, next) {
|
middleware.redirectUidToUserslug = function redirectUidToUserslug(req, res, next) {
|
||||||
var uid = parseInt(req.params.uid, 10);
|
var uid = parseInt(req.params.uid, 10);
|
||||||
if (uid <= 0) {
|
if (uid <= 0) {
|
||||||
return next();
|
return next();
|
||||||
@@ -164,7 +164,7 @@ module.exports = function (middleware) {
|
|||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.redirectMeToUserslug = function (req, res, next) {
|
middleware.redirectMeToUserslug = function redirectMeToUserslug(req, res, next) {
|
||||||
var uid = req.uid;
|
var uid = req.uid;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -180,7 +180,7 @@ module.exports = function (middleware) {
|
|||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
middleware.isAdmin = function (req, res, next) {
|
middleware.isAdmin = function isAdmin(req, res, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.isAdministrator(req.uid, next);
|
user.isAdministrator(req.uid, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user