v1.18.x
barisusakli 11 years ago
parent f377868764
commit 926acd16b2

@ -91,25 +91,32 @@ categoriesController.get = function(req, res, next) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
async.parallel({
exists: function(next) {
categories.exists(cid, next);
},
disabled: function(next) {
categories.getCategoryField(cid, 'disabled', next); categories.getCategoryField(cid, 'disabled', next);
}, },
function(disabled, next) { privileges: function(next) {
if (parseInt(disabled, 10) === 1) {
return next(new Error('[[error:category-disabled]]'));
}
privileges.categories.get(cid, uid, next); privileges.categories.get(cid, uid, next);
}, },
function (privileges, next) { userSettings: function(next) {
if (!privileges.read) { user.getSettings(uid, next);
return next(new Error('[[error:no-privileges]]')); }
}, next);
},
function(results, next) {
if (!results.exists || parseInt(results.disabled, 10) === 1) {
return notFound(req, res);
} }
user.getSettings(uid, function(err, settings) { if (!results.privileges.read) {
if (err) { return notAllowed(req, res);
return next(err);
} }
var settings = results.userSettings;
var topicIndex = 0; var topicIndex = 0;
if (!settings.usePagination) { if (!settings.usePagination) {
topicIndex = Math.max((req.params.topic_index || 1) - (settings.topicsPerPage - 1), 0); topicIndex = Math.max((req.params.topic_index || 1) - (settings.topicsPerPage - 1), 0);
@ -130,11 +137,10 @@ categoriesController.get = function(req, res, next) {
if (err) { if (err) {
return next(err); return next(err);
} }
categoryData.privileges = privileges; categoryData.privileges = results.privileges;
next(null, categoryData); next(null, categoryData);
}); });
}); });
});
}, },
function (categoryData, next) { function (categoryData, next) {
res.locals.metaTags = [ res.locals.metaTags = [
@ -179,7 +185,7 @@ categoriesController.get = function(req, res, next) {
} }
], function (err, data) { ], function (err, data) {
if (err) { if (err) {
return res.locals.isAPI ? res.json(404, 'not-found') : res.redirect(nconf.get('relative_path') + '/404'); return next(err);
} }
if (data.link) { if (data.link) {
@ -193,7 +199,7 @@ categoriesController.get = function(req, res, next) {
} }
data.currentPage = page; data.currentPage = page;
data['feeds:disableRSS'] = meta.config['feeds:disableRSS'] === '1' ? true : false; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
data.csrf = req.csrfToken(); data.csrf = req.csrfToken();
// Paginator for noscript // Paginator for noscript
@ -204,8 +210,27 @@ categoriesController.get = function(req, res, next) {
active: x === parseInt(page, 10) active: x === parseInt(page, 10)
}); });
} }
res.render('category', data); res.render('category', data);
}); });
}; };
function notFound(req, res) {
res.locals.isAPI ? res.json(404, 'not-found') : res.redirect(nconf.get('relative_path') + '/404');
}
function notAllowed(req, res) {
var uid = req.user ? req.user.uid : 0;
if (uid) {
res.locals.isAPI ? res.json(403, 'not-allowed') : res.redirect(nconf.get('relative_path') + '/403');
} else {
if (res.locals.isAPI) {
res.json(401, 'not-authorized');
} else {
req.session.returnTo = req.url;
res.redirect(nconf.get('relative_path') + '/login');
}
}
}
module.exports = categoriesController; module.exports = categoriesController;

Loading…
Cancel
Save