|
|
|
@ -91,25 +91,32 @@ categoriesController.get = function(req, res, next) {
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
exists: function(next) {
|
|
|
|
|
categories.exists(cid, next);
|
|
|
|
|
},
|
|
|
|
|
disabled: function(next) {
|
|
|
|
|
categories.getCategoryField(cid, 'disabled', next);
|
|
|
|
|
},
|
|
|
|
|
function(disabled, next) {
|
|
|
|
|
if (parseInt(disabled, 10) === 1) {
|
|
|
|
|
return next(new Error('[[error:category-disabled]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
privileges: function(next) {
|
|
|
|
|
privileges.categories.get(cid, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (privileges, next) {
|
|
|
|
|
if (!privileges.read) {
|
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
|
userSettings: function(next) {
|
|
|
|
|
user.getSettings(uid, next);
|
|
|
|
|
}
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(results, next) {
|
|
|
|
|
if (!results.exists || parseInt(results.disabled, 10) === 1) {
|
|
|
|
|
return notFound(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getSettings(uid, function(err, settings) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
if (!results.privileges.read) {
|
|
|
|
|
return notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var settings = results.userSettings;
|
|
|
|
|
|
|
|
|
|
var topicIndex = 0;
|
|
|
|
|
if (!settings.usePagination) {
|
|
|
|
|
topicIndex = Math.max((req.params.topic_index || 1) - (settings.topicsPerPage - 1), 0);
|
|
|
|
@ -130,11 +137,10 @@ categoriesController.get = function(req, res, next) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
categoryData.privileges = privileges;
|
|
|
|
|
categoryData.privileges = results.privileges;
|
|
|
|
|
next(null, categoryData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (categoryData, next) {
|
|
|
|
|
res.locals.metaTags = [
|
|
|
|
@ -179,7 +185,7 @@ categoriesController.get = function(req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
], function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return res.locals.isAPI ? res.json(404, 'not-found') : res.redirect(nconf.get('relative_path') + '/404');
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.link) {
|
|
|
|
@ -193,7 +199,7 @@ categoriesController.get = function(req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
// Paginator for noscript
|
|
|
|
@ -204,8 +210,27 @@ categoriesController.get = function(req, res, next) {
|
|
|
|
|
active: x === parseInt(page, 10)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|