added a new middleware and plugin hook

- Middleware added: requireUser, redirects to login if there is no user session.
- Hook added: filter:router.page
v1.18.x
Julian Lam 10 years ago
parent 5d94b00883
commit 5a50a098d8

@ -66,6 +66,15 @@ middleware.pageView = function(req, res, next) {
}
};
middleware.pluginHooks = function(req, res, next) {
async.each(plugins.loadedHooks['filter:router.page'], function(hookObj, next) {
hookObj.method(req, res, next)
}, function(req, res) {
// If it got here, then none of the subscribed hooks did anything, or there were no hooks
next();
});
};
middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
if (!req.user) {
return next();
@ -485,6 +494,14 @@ middleware.exposeUid = function(req, res, next) {
}
};
middleware.requireUser = function(req, res, next) {
if (req.user) {
return next();
}
res.render('403', {});
};
function redirectToLogin(req, res) {
req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
return controllers.helpers.redirect(res, '/login');

@ -3,7 +3,7 @@
var helpers = {};
helpers.setupPageRoute = function(router, name, middleware, middlewares, controller) {
middlewares = middlewares.concat([middleware.pageView]);
middlewares = middlewares.concat([middleware.pageView, middleware.pluginHooks]);
router.get(name, middleware.buildHeader, middlewares, controller);
router.get('/api' + name, middlewares, controller);

Loading…
Cancel
Save