mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
@@ -24,7 +24,7 @@ var fs = require('fs'),
|
||||
|
||||
function userNotFound(res) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json(404, 'user-not-found');
|
||||
res.status(404).json('user-not-found');
|
||||
} else {
|
||||
res.render('404', {
|
||||
error: 'User not found!'
|
||||
@@ -34,7 +34,7 @@ function userNotFound(res) {
|
||||
|
||||
function userNotAllowed(res) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json(403, 'not-allowed');
|
||||
res.status(403).json('not-allowed');
|
||||
} else {
|
||||
res.render('403', {
|
||||
error: 'Not allowed.'
|
||||
|
||||
@@ -54,7 +54,7 @@ apiController.getConfig = function(req, res, next) {
|
||||
|
||||
if (!req.user) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json(200, config);
|
||||
res.status(200).json(config);
|
||||
} else {
|
||||
next(null, config);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ apiController.getConfig = function(req, res, next) {
|
||||
config.topicPostSort = settings.topicPostSort || config.topicPostSort;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(200, config);
|
||||
res.status(200).json(config);
|
||||
} else {
|
||||
next(err, config);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ apiController.renderWidgets = function(req, res, next) {
|
||||
renderedWidgets = [];
|
||||
|
||||
if (!areas.template || !areas.locations) {
|
||||
return res.json(200, {});
|
||||
return res.status(200).json({});
|
||||
}
|
||||
|
||||
widgets.render(uid, {
|
||||
@@ -106,7 +106,7 @@ apiController.renderWidgets = function(req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.json(200, widgets);
|
||||
res.status(200).json(widgets);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -227,17 +227,17 @@ categoriesController.get = function(req, res, next) {
|
||||
};
|
||||
|
||||
categoriesController.notFound = function(req, res) {
|
||||
res.locals.isAPI ? res.json(404, 'not-found') : res.status(404).render('404');
|
||||
res.locals.isAPI ? res.status(404).json('not-found') : res.status(404).render('404');
|
||||
};
|
||||
|
||||
categoriesController.notAllowed = function(req, res) {
|
||||
var uid = req.user ? req.user.uid : 0;
|
||||
if (uid) {
|
||||
res.locals.isAPI ? res.json(403, 'not-allowed') : res.status(403).render('403');
|
||||
res.locals.isAPI ? res.status(403).json('not-allowed') : res.status(403).render('403');
|
||||
} else {
|
||||
if (res.locals.isAPI) {
|
||||
req.session.returnTo = apiToRegular(req.url);
|
||||
res.json(401, 'not-authorized');
|
||||
res.status(401).json('not-authorized');
|
||||
} else {
|
||||
req.session.returnTo = req.url;
|
||||
res.redirect(nconf.get('relative_path') + '/login');
|
||||
|
||||
@@ -49,10 +49,10 @@ topicsController.get = function(req, res, next) {
|
||||
var url = '';
|
||||
if (req.params.post_index > postCount) {
|
||||
url = '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
} else if (req.params.post_index < 1) {
|
||||
url = '/topic/' + req.params.topic_id + '/' + req.params.slug;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ topicsController.teaser = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!canRead) {
|
||||
return res.json(403, '[[error:no-priveges]]');
|
||||
return res.status(403).json('[[error:no-priveges]]');
|
||||
}
|
||||
|
||||
topics.getLatestUndeletedPid(tid, function(err, pid) {
|
||||
@@ -284,7 +284,7 @@ topicsController.teaser = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!pid) {
|
||||
return res.json(404, 'not-found');
|
||||
return res.status(404).json('not-found');
|
||||
}
|
||||
|
||||
posts.getPostSummaryByPids([pid], uid, {stripTags: false}, function(err, posts) {
|
||||
@@ -293,7 +293,7 @@ topicsController.teaser = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!Array.isArray(posts) || !posts.length) {
|
||||
return res.json(404, 'not-found');
|
||||
return res.status(404).json('not-found');
|
||||
}
|
||||
|
||||
res.json(posts[0]);
|
||||
|
||||
@@ -16,7 +16,7 @@ var app,
|
||||
|
||||
middleware.isAdmin = function(req, res, next) {
|
||||
if (!req.user) {
|
||||
return res.json(404, {
|
||||
return res.status(404).json({
|
||||
error: 'not-found'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ var app,
|
||||
middleware.authenticate = function(req, res, next) {
|
||||
if(!req.user) {
|
||||
if (res.locals.isAPI) {
|
||||
return res.json(403, 'not-allowed');
|
||||
return res.status(403).json('not-allowed');
|
||||
} else {
|
||||
return res.redirect(nconf.get('url') + '/403');
|
||||
}
|
||||
@@ -68,7 +68,7 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(302, '/user/' + userslug);
|
||||
res.status(302).json('/user/' + userslug);
|
||||
} else {
|
||||
res.redirect('/user/' + userslug);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ middleware.addSlug = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
var url = name + encodeURI(slug);
|
||||
res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,10 +119,10 @@ middleware.checkTopicIndex = function(req, res, next) {
|
||||
|
||||
if (topicIndex > topicCount) {
|
||||
url = '/category/' + req.params.category_id + '/' + req.params.slug + '/' + topicCount;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
} else if (topicIndex < 1) {
|
||||
url = '/category/' + req.params.category_id + '/' + req.params.slug;
|
||||
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
}
|
||||
next();
|
||||
});
|
||||
@@ -146,7 +146,7 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) {
|
||||
|
||||
if (!callerUID && !!parseInt(meta.config.privateUserInfo, 10)) {
|
||||
if (res.locals.isAPI) {
|
||||
return res.json(403, 'not-allowed');
|
||||
return res.status(403).json('not-allowed');
|
||||
} else {
|
||||
req.session.returnTo = req.url;
|
||||
return res.redirect('login');
|
||||
@@ -171,7 +171,7 @@ middleware.checkAccountPermissions = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
return res.locals.isAPI ? res.json(404, 'not-found') : res.redirect(nconf.get('relative_path') + '/404');
|
||||
return res.locals.isAPI ? res.status(404).json('not-found') : res.redirect(nconf.get('relative_path') + '/404');
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) === callerUID) {
|
||||
@@ -187,7 +187,7 @@ middleware.checkAccountPermissions = function(req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
res.locals.isAPI ? res.json(403, 'not-allowed') : res.redirect(nconf.get('relative_path') + '/403');
|
||||
res.locals.isAPI ? res.status(403).json('not-allowed') : res.redirect(nconf.get('relative_path') + '/403');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -43,12 +43,12 @@ function upload(req, res, filesIterator, next) {
|
||||
deleteTempFiles(files);
|
||||
|
||||
if (err) {
|
||||
return res.send(500, err.message);
|
||||
return res.status(500).send(err.message);
|
||||
}
|
||||
|
||||
// IE8 - send it as text/html so browser won't trigger a file download for the json response
|
||||
// malsup.com/jquery/form/#file-upload
|
||||
res.send(200, req.xhr ? images : JSON.stringify(images));
|
||||
res.status(200).send(req.xhr ? images : JSON.stringify(images));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
req.logout();
|
||||
}
|
||||
|
||||
res.send(200);
|
||||
res.status(200).send('');
|
||||
}
|
||||
|
||||
function login(req, res, next) {
|
||||
@@ -80,7 +80,7 @@
|
||||
};
|
||||
|
||||
if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) {
|
||||
return res.send(404);
|
||||
return res.status(404).send('');
|
||||
}
|
||||
|
||||
if (req.body.username && utils.isEmailValid(req.body.username)) {
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
function register(req, res) {
|
||||
if(meta.config.allowRegistration !== undefined && parseInt(meta.config.allowRegistration, 10) === 0) {
|
||||
return res.send(403);
|
||||
return res.status(403).send('');
|
||||
}
|
||||
|
||||
var userData = {};
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
if (data) {
|
||||
res.send(data);
|
||||
} else {
|
||||
res.json(404, {
|
||||
res.status(404).json({
|
||||
error: "User doesn't exist!"
|
||||
});
|
||||
}
|
||||
@@ -30,7 +30,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
if (data) {
|
||||
res.send(data);
|
||||
} else {
|
||||
res.send(404, "Category doesn't exist!");
|
||||
res.status(404).send("Category doesn't exist!");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -40,7 +40,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
if (data) {
|
||||
res.send(data);
|
||||
} else {
|
||||
res.send(404, "Topic doesn't exist!");
|
||||
res.status(404).send("Topic doesn't exist!");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -50,7 +50,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
if (data) {
|
||||
res.send(data);
|
||||
} else {
|
||||
res.send(404, "Post doesn't exist!");
|
||||
res.status(404).send("Post doesn't exist!");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -183,7 +183,7 @@ function catch404(req, res, next) {
|
||||
res.status(404);
|
||||
|
||||
if (isClientScript.test(req.url)) {
|
||||
res.type('text/javascript').send(200, '');
|
||||
res.type('text/javascript').status(200).send('');
|
||||
} else if (isLanguage.test(req.url)) {
|
||||
res.json(200, {});
|
||||
} else if (req.accepts('html')) {
|
||||
|
||||
@@ -24,11 +24,11 @@ function sendSourceMap(req, res) {
|
||||
}
|
||||
|
||||
function sendStylesheet(req, res, next) {
|
||||
res.type('text/css').send(200, meta.css.cache);
|
||||
res.type('text/css').status(200).send(meta.css.cache);
|
||||
}
|
||||
|
||||
function sendACPStylesheet(req, res, next) {
|
||||
res.type('text/css').send(200, meta.css.acpCache);
|
||||
res.type('text/css').status(200).send(meta.css.acpCache);
|
||||
}
|
||||
|
||||
function setupPluginSourceMapping(app) {
|
||||
|
||||
Reference in New Issue
Block a user