mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 00:10:25 +01:00
moved notFound notAllowed to helpers
This commit is contained in:
35
src/controllers/helpers.js
Normal file
35
src/controllers/helpers.js
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var helpers = {};
|
||||
|
||||
helpers.notFound = function(res) {
|
||||
if (res.locals.isAPI) {
|
||||
res.status(404).json('not-found');
|
||||
} else {
|
||||
res.status(404).render('404');
|
||||
}
|
||||
};
|
||||
|
||||
helpers.notAllowed = function(req, res) {
|
||||
var uid = req.user ? req.user.uid : 0;
|
||||
|
||||
if (uid) {
|
||||
if (res.locals.isAPI) {
|
||||
res.status(403).json('not-allowed');
|
||||
} else {
|
||||
res.status(403).render('403');
|
||||
}
|
||||
} else {
|
||||
if (res.locals.isAPI) {
|
||||
req.session.returnTo = req.url.replace(/^\/api/, '');
|
||||
res.status(401).json('not-authorized');
|
||||
} else {
|
||||
req.session.returnTo = req.url;
|
||||
res.redirect(nconf.get('relative_path') + '/login');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = helpers;
|
||||
Reference in New Issue
Block a user