Skip to content

Node.js based forum software built for the modern web

async

Barış Soner Uşaklı1a6e576483c1
diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js
index a1f0e31486..7a3bc192b6 100644
--- a/src/middleware/middleware.js
+++ b/src/middleware/middleware.js
@@ -126,32 +126,29 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
middleware.checkAccountPermissions = function(req, res, next) {
// This middleware ensures that only the requested user and admins can pass
- middleware.authenticate(req, res, function(err) {
- if (err) {
- return next(err);
- }
-
- user.getUidByUserslug(req.params.userslug, function (err, uid) {
- if (err) {
- return next(err);
- }
-
+ async.waterfall([
+ function (next) {
+ middleware.authenticate(req, res, next);
+ },
+ function (next) {
+ user.getUidByUserslug(req.params.userslug, next);
+ },
+ function (uid, next) {
if (!uid) {
return controllers.helpers.notFound(req, res);
}
if (parseInt(uid, 10) === req.uid) {
- return next();
+ return next(null, true);
}
- user.isAdministrator(req.uid, function(err, isAdmin) {
- if (err || isAdmin) {
- return next(err);
- }
-
- controllers.helpers.notAllowed(req, res);
- });
- });
+ user.isAdministrator(req.uid, next);
+ }
+ ], function (err, allowed) {
+ if (err || allowed) {
+ return next(err);
+ }
+ controllers.helpers.notAllowed(req, res);
});
};