updated checkAccountPermissions to call requireUser, and added new hook for plugins to handle auth login

v1.18.x
Julian Lam
parent 1ade973e56
commit 40834cc010

@ -32,6 +32,12 @@ var app,
middleware.authenticate = function(req, res, next) { middleware.authenticate = function(req, res, next) {
if (req.user) { if (req.user) {
return next(); return next();
} else if (plugins.hasListeners('action:middleware.authenticate')) {
return plugins.fireHook('action:middleware.authenticate', {
req: req,
res: res,
next: next
});
} }
controllers.helpers.notAllowed(req, res); controllers.helpers.notAllowed(req, res);
@ -124,29 +130,31 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
middleware.checkAccountPermissions = function(req, res, next) { middleware.checkAccountPermissions = function(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
if (!req.uid) { middleware.authenticate(req, res, function(err) {
return controllers.helpers.notAllowed(req, res);
}
user.getUidByUserslug(req.params.userslug, function (err, uid) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (!uid) { user.getUidByUserslug(req.params.userslug, function (err, uid) {
return controllers.helpers.notFound(req, res); if (err) {
} return next(err);
}
if (parseInt(uid, 10) === req.uid) { if (!uid) {
return next(); return controllers.helpers.notFound(req, res);
} }
user.isAdministrator(req.uid, function(err, isAdmin) { if (parseInt(uid, 10) === req.uid) {
if (err || isAdmin) { return next();
return next(err);
} }
controllers.helpers.notAllowed(req, res); user.isAdministrator(req.uid, function(err, isAdmin) {
if (err || isAdmin) {
return next(err);
}
controllers.helpers.notAllowed(req, res);
});
}); });
}); });
}; };

Loading…
Cancel
Save