added req.uid user id for logged in users, 0 for guests

This commit is contained in:
barisusakli
2015-04-01 00:23:57 -04:00
parent 878e548296
commit 2fd4bcde3f
17 changed files with 93 additions and 134 deletions

View File

@@ -25,9 +25,7 @@ function hasCategoryPrivileges(req, res, next) {
}
function hasPrivileges(method, id, req, res, next) {
var uid = req.user ? req.user.uid || 0 : 0;
method('read', id, uid, function(err, canRead) {
method('read', id, req.uid, function(err, canRead) {
if (err) {
return next(err);
}
@@ -42,14 +40,13 @@ function hasPrivileges(method, id, req, res, next) {
function generateForTopic(req, res, next) {
var tid = req.params.topic_id;
var uid = req.user ? req.user.uid : 0;
privileges.topics.get(tid, uid, function(err, userPrivileges) {
privileges.topics.get(tid, req.uid, function(err, userPrivileges) {
if (err) {
return next(err);
}
topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', uid, 0, 25, false, function (err, topicData) {
topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', req.uid, 0, 25, false, function (err, topicData) {
if (err) {
return next(err);
}
@@ -122,14 +119,14 @@ function generateForUserTopics(req, res, next) {
function generateForCategory(req, res, next) {
var cid = req.params.category_id;
var uid = req.user ? req.user.uid : 0;
categories.getCategoryById({
cid: cid,
set: 'cid:' + cid + ':tids',
reverse: true,
start: 0,
stop: 25,
uid: uid
uid: req.uid
}, function (err, categoryData) {
if (err) {
return next(err);
@@ -159,7 +156,6 @@ function generateForRecent(req, res, next) {
}
function generateForPopular(req, res, next) {
var uid = req.user ? req.user.uid : 0;
var terms = {
daily: 'day',
weekly: 'week',
@@ -168,7 +164,7 @@ function generateForPopular(req, res, next) {
};
var term = terms[req.params.term] || 'day';
topics.getPopular(term, uid, 19, function(err, topics) {
topics.getPopular(term, req.uid, 19, function(err, topics) {
if (err) {
return next(err);
}
@@ -196,8 +192,7 @@ function disabledRSS(req, res, next) {
}
function generateForTopics(options, set, req, res, next) {
var uid = req.user ? req.user.uid : 0;
topics.getTopicsFromSet(set, uid, 0, 19, function (err, data) {
topics.getTopicsFromSet(set, req.uid, 0, 19, function (err, data) {
if (err) {
return next(err);
}
@@ -239,8 +234,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
}
function generateForRecentPosts(req, res, next) {
var uid = req.user ? req.user.uid : 0;
posts.getRecentPosts(uid, 0, 19, 'month', function(err, posts) {
posts.getRecentPosts(req.uid, 0, 19, 'month', function(err, posts) {
if (err) {
return next(err);
}
@@ -257,7 +251,6 @@ function generateForRecentPosts(req, res, next) {
}
function generateForCategoryRecentPosts(req, res, next) {
var uid = req.user ? req.user.uid : 0;
var cid = req.params.category_id;
async.parallel({
@@ -265,7 +258,7 @@ function generateForCategoryRecentPosts(req, res, next) {
categories.getCategoryData(cid, next);
},
posts: function(next) {
categories.getRecentReplies(cid, uid, 20, next);
categories.getRecentReplies(cid, req.uid, 20, next);
}
}, function(err, results) {
if (err) {