helpers.notAllowed hook

v1.18.x
psychobunny 9 years ago
parent 41af78dcd2
commit 371abba13b

@ -12,29 +12,35 @@ var meta = require('../meta');
var helpers = {};
helpers.notAllowed = function(req, res, error) {
if (req.uid) {
if (res.locals.isAPI) {
res.status(403).json({
path: req.path.replace(/^\/api/, ''),
loggedIn: !!req.uid, error: error,
title: '[[global:403.title]]'
});
} else {
res.status(403).render('403', {
path: req.path,
loggedIn: !!req.uid, error: error,
title: '[[global:403.title]]'
});
}
} else {
if (res.locals.isAPI) {
req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
res.status(401).json('not-authorized');
plugins.fireHook('filter:helpers.notAllowed', {
req: req,
res: res,
error: error
}, function(err, data) {
if (req.uid) {
if (res.locals.isAPI) {
res.status(403).json({
path: req.path.replace(/^\/api/, ''),
loggedIn: !!req.uid, error: error,
title: '[[global:403.title]]'
});
} else {
res.status(403).render('403', {
path: req.path,
loggedIn: !!req.uid, error: error,
title: '[[global:403.title]]'
});
}
} else {
req.session.returnTo = nconf.get('relative_path') + req.url;
res.redirect(nconf.get('relative_path') + '/login');
if (res.locals.isAPI) {
req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
res.status(401).json('not-authorized');
} else {
req.session.returnTo = nconf.get('relative_path') + req.url;
res.redirect(nconf.get('relative_path') + '/login');
}
}
}
});
};
helpers.redirect = function(res, url) {

Loading…
Cancel
Save