mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	added req.uid user id for logged in users, 0 for guests
This commit is contained in:
		| @@ -120,8 +120,7 @@ accountsController.getUserByUID = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| accountsController.getAccount = function(req, res, next) { | accountsController.getAccount = function(req, res, next) { | ||||||
| 	var lowercaseSlug = req.params.userslug.toLowerCase(), | 	var lowercaseSlug = req.params.userslug.toLowerCase(); | ||||||
| 		callerUID = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
|  |  | ||||||
| 	if (req.params.userslug !== lowercaseSlug) { | 	if (req.params.userslug !== lowercaseSlug) { | ||||||
| 		if (res.locals.isAPI) { | 		if (res.locals.isAPI) { | ||||||
| @@ -131,7 +130,7 @@ accountsController.getAccount = function(req, res, next) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) { | 	getUserDataByUserSlug(req.params.userslug, req.uid, function (err, userData) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -140,19 +139,19 @@ accountsController.getAccount = function(req, res, next) { | |||||||
| 			return helpers.notFound(req, res); | 			return helpers.notFound(req, res); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (callerUID !== parseInt(userData.uid, 10)) { | 		if (req.uid !== parseInt(userData.uid, 10)) { | ||||||
| 			user.incrementUserFieldBy(userData.uid, 'profileviews', 1); | 			user.incrementUserFieldBy(userData.uid, 'profileviews', 1); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		async.parallel({ | 		async.parallel({ | ||||||
| 			isFollowing: function(next) { | 			isFollowing: function(next) { | ||||||
| 				user.isFollowing(callerUID, userData.theirid, next); | 				user.isFollowing(req.uid, userData.theirid, next); | ||||||
| 			}, | 			}, | ||||||
| 			posts: function(next) { | 			posts: function(next) { | ||||||
| 				posts.getPostsFromSet('uid:' + userData.theirid + ':posts', callerUID, 0, 9, next); | 				posts.getPostsFromSet('uid:' + userData.theirid + ':posts', req.uid, 0, 9, next); | ||||||
| 			}, | 			}, | ||||||
| 			signature: function(next) { | 			signature: function(next) { | ||||||
| 				postTools.parseSignature(userData, callerUID, next); | 				postTools.parseSignature(userData, req.uid, next); | ||||||
| 			} | 			} | ||||||
| 		}, function(err, results) { | 		}, function(err, results) { | ||||||
| 			if(err) { | 			if(err) { | ||||||
| @@ -170,7 +169,7 @@ accountsController.getAccount = function(req, res, next) { | |||||||
| 				userData.profileviews = 1; | 				userData.profileviews = 1; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			plugins.fireHook('filter:user.account', {userData: userData, uid: callerUID}, function(err, data) { | 			plugins.fireHook('filter:user.account', {userData: userData, uid: req.uid}, function(err, data) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return next(err); | 					return next(err); | ||||||
| 				} | 				} | ||||||
| @@ -189,12 +188,11 @@ accountsController.getFollowers = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| function getFollow(tpl, name, req, res, next) { | function getFollow(tpl, name, req, res, next) { | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
| 	var userData; | 	var userData; | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function(next) { | 		function(next) { | ||||||
| 			getUserDataByUserSlug(req.params.userslug, callerUID, next); | 			getUserDataByUserSlug(req.params.userslug, req.uid, next); | ||||||
| 		}, | 		}, | ||||||
| 		function(data, next) { | 		function(data, next) { | ||||||
| 			userData = data; | 			userData = data; | ||||||
| @@ -205,7 +203,7 @@ function getFollow(tpl, name, req, res, next) { | |||||||
| 			user[method](userData.uid, 0, 49, next); | 			user[method](userData.uid, 0, 49, next); | ||||||
| 		} | 		} | ||||||
| 	], function(err, users) { | 	], function(err, users) { | ||||||
| 		if(err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -233,9 +231,7 @@ accountsController.getTopics = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| accountsController.getGroups = function(req, res, next) { | accountsController.getGroups = function(req, res, next) { | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; | 	accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) { | ||||||
|  |  | ||||||
| 	accountsController.getBaseUser(req.params.userslug, callerUID, function(err, userData) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -257,9 +253,7 @@ accountsController.getGroups = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| function getFromUserSet(tpl, set, method, type, req, res, next) { | function getFromUserSet(tpl, set, method, type, req, res, next) { | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; | 	accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) { | ||||||
|  |  | ||||||
| 	accountsController.getBaseUser(req.params.userslug, callerUID, function(err, userData) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -268,7 +262,7 @@ function getFromUserSet(tpl, set, method, type, req, res, next) { | |||||||
| 			return helpers.notFound(req, res); | 			return helpers.notFound(req, res); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		method('uid:' + userData.uid + ':' + set, callerUID, 0, 19, function(err, data) { | 		method('uid:' + userData.uid + ':' + set, req.uid, 0, 19, function(err, data) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return next(err); | 				return next(err); | ||||||
| 			} | 			} | ||||||
| @@ -317,11 +311,10 @@ accountsController.getBaseUser = function(userslug, callerUID, callback) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| accountsController.accountEdit = function(req, res, next) { | accountsController.accountEdit = function(req, res, next) { | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
| 	var userData; | 	var userData; | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function(next) { | 		function(next) { | ||||||
| 			getUserDataByUserSlug(req.params.userslug, callerUID, next); | 			getUserDataByUserSlug(req.params.userslug, req.uid, next); | ||||||
| 		}, | 		}, | ||||||
| 		function(data, next) { | 		function(data, next) { | ||||||
| 			userData = data; | 			userData = data; | ||||||
| @@ -339,9 +332,7 @@ accountsController.accountEdit = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| accountsController.accountSettings = function(req, res, next) { | accountsController.accountSettings = function(req, res, next) { | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; | 	accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) { | ||||||
|  |  | ||||||
| 	accountsController.getBaseUser(req.params.userslug, callerUID, function(err, userData) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -380,7 +371,7 @@ accountsController.uploadPicture = function (req, res, next) { | |||||||
| 	var userPhoto = req.files.files[0]; | 	var userPhoto = req.files.files[0]; | ||||||
| 	var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256; | 	var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256; | ||||||
| 	var extension = path.extname(userPhoto.name); | 	var extension = path.extname(userPhoto.name); | ||||||
| 	var updateUid = req.user ? req.user.uid : 0; | 	var updateUid = req.uid; | ||||||
| 	var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 128; | 	var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 128; | ||||||
| 	var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1; | 	var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1; | ||||||
|  |  | ||||||
| @@ -412,7 +403,7 @@ accountsController.uploadPicture = function (req, res, next) { | |||||||
| 				return next(); | 				return next(); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			user.isAdministrator(req.user.uid, function(err, isAdmin) { | 			user.isAdministrator(req.uid, function(err, isAdmin) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return next(err); | 					return next(err); | ||||||
| 				} | 				} | ||||||
| @@ -471,7 +462,7 @@ accountsController.uploadPicture = function (req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| accountsController.getNotifications = function(req, res, next) { | accountsController.getNotifications = function(req, res, next) { | ||||||
| 	user.notifications.getAll(req.user.uid, 40, function(err, notifications) { | 	user.notifications.getAll(req.uid, 40, function(err, notifications) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -144,11 +144,10 @@ adminController.categories.get = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| adminController.categories.getAll = function(req, res, next) { | adminController.categories.getAll = function(req, res, next) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0, | 	var	active = [], | ||||||
| 		active = [], |  | ||||||
| 		disabled = []; | 		disabled = []; | ||||||
|  |  | ||||||
| 	categories.getAllCategories(uid, function (err, categoryData) { | 	categories.getAllCategories(req.uid, function (err, categoryData) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -181,17 +180,17 @@ adminController.flags.get = function(req, res, next) { | |||||||
| 		} | 		} | ||||||
| 		res.render('admin/manage/flags', {posts: posts, next: stop + 1, byUsername: byUsername}); | 		res.render('admin/manage/flags', {posts: posts, next: stop + 1, byUsername: byUsername}); | ||||||
| 	} | 	} | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
| 	var sortBy = req.query.sortBy || 'count'; | 	var sortBy = req.query.sortBy || 'count'; | ||||||
| 	var byUsername = req.query.byUsername || ''; | 	var byUsername = req.query.byUsername || ''; | ||||||
| 	var start = 0; | 	var start = 0; | ||||||
| 	var stop = 19; | 	var stop = 19; | ||||||
|  |  | ||||||
| 	if (byUsername) { | 	if (byUsername) { | ||||||
| 		posts.getUserFlags(byUsername, sortBy, uid, start, stop, done); | 		posts.getUserFlags(byUsername, sortBy, req.uid, start, stop, done); | ||||||
| 	} else { | 	} else { | ||||||
| 		var set = sortBy === 'count' ? 'posts:flags:count' : 'posts:flagged'; | 		var set = sortBy === 'count' ? 'posts:flags:count' : 'posts:flagged'; | ||||||
| 		posts.getFlags(set, uid, start, stop, done); | 		posts.getFlags(set, req.uid, start, stop, done); | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,8 +31,7 @@ usersController.banned = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| function getUsers(set, req, res, next) { | function getUsers(set, req, res, next) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; | 	user.getUsersFromSet(set, req.uid, 0, 49, function(err, users) { | ||||||
| 	user.getUsersFromSet(set, uid, 0, 49, function(err, users) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -45,7 +44,7 @@ function getUsers(set, req, res, next) { | |||||||
| 			search_display: 'hidden', | 			search_display: 'hidden', | ||||||
| 			loadmore_display: 'block', | 			loadmore_display: 'block', | ||||||
| 			users: users, | 			users: users, | ||||||
| 			yourid: req.user.uid, | 			yourid: req.uid, | ||||||
| 			requireEmailConfirmation: parseInt(meta.config.requireEmailConfirmation, 10) === 1 | 			requireEmailConfirmation: parseInt(meta.config.requireEmailConfirmation, 10) === 1 | ||||||
| 		}); | 		}); | ||||||
| 	}); | 	}); | ||||||
|   | |||||||
| @@ -98,7 +98,6 @@ apiController.getConfig = function(req, res, next) { | |||||||
|  |  | ||||||
| apiController.renderWidgets = function(req, res, next) { | apiController.renderWidgets = function(req, res, next) { | ||||||
| 	var async = require('async'), | 	var async = require('async'), | ||||||
| 		uid = req.user ? req.user.uid : 0, |  | ||||||
| 		areas = { | 		areas = { | ||||||
| 			template: req.query.template, | 			template: req.query.template, | ||||||
| 			locations: req.query.locations, | 			locations: req.query.locations, | ||||||
| @@ -110,7 +109,7 @@ apiController.renderWidgets = function(req, res, next) { | |||||||
| 		return res.status(200).json({}); | 		return res.status(200).json({}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	widgets.render(uid, { | 	widgets.render(req.uid, { | ||||||
| 		template: areas.template, | 		template: areas.template, | ||||||
| 		url: areas.url, | 		url: areas.url, | ||||||
| 		locations: areas.locations | 		locations: areas.locations | ||||||
|   | |||||||
| @@ -17,9 +17,8 @@ var categoriesController = {}, | |||||||
| 	utils = require('../../public/src/utils'); | 	utils = require('../../public/src/utils'); | ||||||
|  |  | ||||||
| categoriesController.recent = function(req, res, next) { | categoriesController.recent = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | ||||||
| 	topics.getTopicsFromSet('topics:recent', uid, 0, stop, function(err, data) { | 	topics.getTopicsFromSet('topics:recent', req.uid, 0, stop, function(err, data) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -34,7 +33,6 @@ categoriesController.recent = function(req, res, next) { | |||||||
| var anonCache = {}, lastUpdateTime = 0; | var anonCache = {}, lastUpdateTime = 0; | ||||||
|  |  | ||||||
| categoriesController.popular = function(req, res, next) { | categoriesController.popular = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var terms = { | 	var terms = { | ||||||
| 		daily: 'day', | 		daily: 'day', | ||||||
| 		weekly: 'week', | 		weekly: 'week', | ||||||
| @@ -43,13 +41,13 @@ categoriesController.popular = function(req, res, next) { | |||||||
| 	}; | 	}; | ||||||
| 	var term = terms[req.params.term] || 'day'; | 	var term = terms[req.params.term] || 'day'; | ||||||
|  |  | ||||||
| 	if (uid === 0) { | 	if (!req.uid) { | ||||||
| 		if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) { | 		if (anonCache[term] && (Date.now() - lastUpdateTime) < 60 * 60 * 1000) { | ||||||
| 			return res.render('popular', anonCache[term]); | 			return res.render('popular', anonCache[term]); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	topics.getPopular(term, uid, meta.config.topicsPerList, function(err, topics) { | 	topics.getPopular(term, req.uid, meta.config.topicsPerList, function(err, topics) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -61,7 +59,7 @@ categoriesController.popular = function(req, res, next) { | |||||||
| 			breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:header.popular]]'}]) | 			breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:header.popular]]'}]) | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		if (uid === 0) { | 		if (!req.uid) { | ||||||
| 			anonCache[term] = data; | 			anonCache[term] = data; | ||||||
| 			lastUpdateTime = Date.now(); | 			lastUpdateTime = Date.now(); | ||||||
| 		} | 		} | ||||||
| @@ -71,9 +69,8 @@ categoriesController.popular = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| categoriesController.unread = function(req, res, next) { | categoriesController.unread = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | ||||||
| 	topics.getUnreadTopics(uid, 0, stop, function (err, data) { | 	topics.getUnreadTopics(req.uid, 0, stop, function (err, data) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -84,10 +81,8 @@ categoriesController.unread = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| categoriesController.unreadTotal = function(req, res, next) { | categoriesController.unreadTotal = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; | 	topics.getTotalUnread(req.uid, function (err, data) { | ||||||
|  | 		if (err) { | ||||||
| 	topics.getTotalUnread(uid, function (err, data) { |  | ||||||
| 		if(err) { |  | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -122,11 +117,10 @@ categoriesController.list = function(req, res, next) { | |||||||
| 			next(null); | 			next(null); | ||||||
| 		}, | 		}, | ||||||
| 		categories: function (next) { | 		categories: function (next) { | ||||||
| 			var uid = req.user ? req.user.uid : 0; |  | ||||||
| 			var categoryData; | 			var categoryData; | ||||||
| 			async.waterfall([ | 			async.waterfall([ | ||||||
| 				function(next) { | 				function(next) { | ||||||
| 					categories.getCategoriesByPrivilege(uid, 'find', next); | 					categories.getCategoriesByPrivilege(req.uid, 'find', next); | ||||||
| 				}, | 				}, | ||||||
| 				function(_categoryData, next) { | 				function(_categoryData, next) { | ||||||
| 					categoryData = _categoryData; | 					categoryData = _categoryData; | ||||||
| @@ -143,7 +137,7 @@ categoriesController.list = function(req, res, next) { | |||||||
| 						return category && !category.parent; | 						return category && !category.parent; | ||||||
| 					}); | 					}); | ||||||
|  |  | ||||||
| 					categories.getRecentTopicReplies(allCategories, uid, next); | 					categories.getRecentTopicReplies(allCategories, req.uid, next); | ||||||
| 				} | 				} | ||||||
| 			], function(err) { | 			], function(err) { | ||||||
| 				next(err, categoryData); | 				next(err, categoryData); | ||||||
| @@ -166,7 +160,6 @@ categoriesController.list = function(req, res, next) { | |||||||
| categoriesController.get = function(req, res, next) { | categoriesController.get = function(req, res, next) { | ||||||
| 	var cid = req.params.category_id, | 	var cid = req.params.category_id, | ||||||
| 		page = req.query.page || 1, | 		page = req.query.page || 1, | ||||||
| 		uid = req.user ? req.user.uid : 0, |  | ||||||
| 		userPrivileges; | 		userPrivileges; | ||||||
|  |  | ||||||
| 	if (req.params.topic_index && !utils.isNumber(req.params.topic_index)) { | 	if (req.params.topic_index && !utils.isNumber(req.params.topic_index)) { | ||||||
| @@ -183,10 +176,10 @@ categoriesController.get = function(req, res, next) { | |||||||
| 					categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next); | 					categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next); | ||||||
| 				}, | 				}, | ||||||
| 				privileges: function(next) { | 				privileges: function(next) { | ||||||
| 					privileges.categories.get(cid, uid, next); | 					privileges.categories.get(cid, req.uid, next); | ||||||
| 				}, | 				}, | ||||||
| 				userSettings: function(next) { | 				userSettings: function(next) { | ||||||
| 					user.getSettings(uid, next); | 					user.getSettings(req.uid, next); | ||||||
| 				} | 				} | ||||||
| 			}, next); | 			}, next); | ||||||
| 		}, | 		}, | ||||||
| @@ -240,7 +233,7 @@ categoriesController.get = function(req, res, next) { | |||||||
| 				reverse: reverse, | 				reverse: reverse, | ||||||
| 				start: start, | 				start: start, | ||||||
| 				stop: stop, | 				stop: stop, | ||||||
| 				uid: uid | 				uid: req.uid | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		function(payload, next) { | 		function(payload, next) { | ||||||
| @@ -276,7 +269,7 @@ categoriesController.get = function(req, res, next) { | |||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		function(categoryData, next) { | 		function(categoryData, next) { | ||||||
| 			categories.getRecentTopicReplies(categoryData.children, uid, function(err) { | 			categories.getRecentTopicReplies(categoryData.children, req.uid, function(err) { | ||||||
| 				next(err, categoryData); | 				next(err, categoryData); | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| @@ -303,7 +296,7 @@ categoriesController.get = function(req, res, next) { | |||||||
| 				} | 				} | ||||||
| 			]; | 			]; | ||||||
|  |  | ||||||
| 			if(categoryData.backgroundImage) { | 			if (categoryData.backgroundImage) { | ||||||
| 				res.locals.metaTags.push({ | 				res.locals.metaTags.push({ | ||||||
| 					name: 'og:image', | 					name: 'og:image', | ||||||
| 					content: categoryData.backgroundImage | 					content: categoryData.backgroundImage | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ groupsController.list = function(req, res, next) { | |||||||
| 	groups.list({ | 	groups.list({ | ||||||
| 		truncateUserList: true, | 		truncateUserList: true, | ||||||
| 		expand: true, | 		expand: true, | ||||||
| 		uid: req.user ? parseInt(req.user.uid, 10) : 0 | 		uid: req.uid | ||||||
| 	}, function(err, groups) { | 	}, function(err, groups) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| @@ -25,12 +25,12 @@ groupsController.list = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| groupsController.details = function(req, res, next) { | groupsController.details = function(req, res, next) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		async.apply(groups.exists, res.locals.groupName), | 		async.apply(groups.exists, res.locals.groupName), | ||||||
| 		function(exists, next) { | 		function(exists, next) { | ||||||
| 			if (!exists) { return next(undefined, null); } | 			if (!exists) { | ||||||
|  | 				return next(undefined, null); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			// Ensure the group isn't hidden either | 			// Ensure the group isn't hidden either | ||||||
| 			groups.isHidden(res.locals.groupName, next); | 			groups.isHidden(res.locals.groupName, next); | ||||||
| @@ -43,8 +43,8 @@ groupsController.details = function(req, res, next) { | |||||||
| 			} else { | 			} else { | ||||||
| 				// If not, only members are granted access | 				// If not, only members are granted access | ||||||
| 				async.parallel([ | 				async.parallel([ | ||||||
| 					async.apply(groups.isMember, uid, res.locals.groupName), | 					async.apply(groups.isMember, req.uid, res.locals.groupName), | ||||||
| 					async.apply(groups.isInvited, uid, res.locals.groupName) | 					async.apply(groups.isInvited, req.uid, res.locals.groupName) | ||||||
| 				], function(err, checks) { | 				], function(err, checks) { | ||||||
| 					next(err, checks[0] || checks[1]); | 					next(err, checks[0] || checks[1]); | ||||||
| 				}); | 				}); | ||||||
| @@ -63,11 +63,11 @@ groupsController.details = function(req, res, next) { | |||||||
| 			group: function(next) { | 			group: function(next) { | ||||||
| 				groups.get(res.locals.groupName, { | 				groups.get(res.locals.groupName, { | ||||||
| 					expand: true, | 					expand: true, | ||||||
| 					uid: uid | 					uid: req.uid | ||||||
| 				}, next); | 				}, next); | ||||||
| 			}, | 			}, | ||||||
| 			posts: function(next) { | 			posts: function(next) { | ||||||
| 				groups.getLatestMemberPosts(res.locals.groupName, 10, uid, next); | 				groups.getLatestMemberPosts(res.locals.groupName, 10, req.uid, next); | ||||||
| 			} | 			} | ||||||
| 		}, function(err, results) { | 		}, function(err, results) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| @@ -84,13 +84,12 @@ groupsController.details = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| groupsController.members = function(req, res, next) { | groupsController.members = function(req, res, next) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function(next) { | 		function(next) { | ||||||
| 			groups.getGroupNameByGroupSlug(req.params.slug, next); | 			groups.getGroupNameByGroupSlug(req.params.slug, next); | ||||||
| 		}, | 		}, | ||||||
| 		function(groupName, next) { | 		function(groupName, next) { | ||||||
| 			user.getUsersFromSet('group:' + groupName + ':members', uid, 0, 49, next); | 			user.getUsersFromSet('group:' + groupName + ':members', req.uid, 0, 49, next); | ||||||
| 		}, | 		}, | ||||||
| 	], function(err, users) { | 	], function(err, users) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
|   | |||||||
| @@ -26,13 +26,11 @@ helpers.notFound = function(req, res, error) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| helpers.notAllowed = function(req, res, error) { | helpers.notAllowed = function(req, res, error) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; | 	if (req.uid) { | ||||||
|  |  | ||||||
| 	if (uid) { |  | ||||||
| 		if (res.locals.isAPI) { | 		if (res.locals.isAPI) { | ||||||
| 			res.status(403).json({path: req.path.replace(/^\/api/, ''), loggedIn: !!uid, error: error}); | 			res.status(403).json({path: req.path.replace(/^\/api/, ''), loggedIn: !!req.uid, error: error}); | ||||||
| 		} else { | 		} else { | ||||||
| 			res.status(403).render('403', {path: req.path, loggedIn: !!uid, error: error}); | 			res.status(403).render('403', {path: req.path, loggedIn: !!req.uid, error: error}); | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		if (res.locals.isAPI) { | 		if (res.locals.isAPI) { | ||||||
|   | |||||||
| @@ -8,10 +8,9 @@ var async = require('async'), | |||||||
| 	postsController = {}; | 	postsController = {}; | ||||||
|  |  | ||||||
| postsController.getPost = function(req, res, next) { | postsController.getPost = function(req, res, next) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid) : 0; |  | ||||||
| 	async.parallel({ | 	async.parallel({ | ||||||
| 		canRead: function(next) { | 		canRead: function(next) { | ||||||
| 			privileges.posts.can('read', req.params.pid, uid, next); | 			privileges.posts.can('read', req.params.pid, req.uid, next); | ||||||
| 		}, | 		}, | ||||||
| 		postData: function(next) { | 		postData: function(next) { | ||||||
| 			posts.getPostData(req.params.pid, next); | 			posts.getPostData(req.params.pid, next); | ||||||
|   | |||||||
| @@ -15,10 +15,9 @@ searchController.search = function(req, res, next) { | |||||||
| 		return helpers.notFound(req, res); | 		return helpers.notFound(req, res); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]); | 	var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]); | ||||||
|  |  | ||||||
| 	categories.getCategoriesByPrivilege(uid, 'read', function(err, categories) { | 	categories.getCategoriesByPrivilege(req.uid, 'read', function(err, categories) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -42,7 +41,7 @@ searchController.search = function(req, res, next) { | |||||||
| 			sortBy: req.query.sortBy, | 			sortBy: req.query.sortBy, | ||||||
| 			sortDirection: req.query.sortDirection, | 			sortDirection: req.query.sortDirection, | ||||||
| 			page: page, | 			page: page, | ||||||
| 			uid: uid | 			uid: req.uid | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		search.search(data, function(err, results) { | 		search.search(data, function(err, results) { | ||||||
|   | |||||||
| @@ -10,7 +10,6 @@ var tagsController = {}, | |||||||
|  |  | ||||||
| tagsController.getTag = function(req, res, next) { | tagsController.getTag = function(req, res, next) { | ||||||
| 	var tag = validator.escape(req.params.tag); | 	var tag = validator.escape(req.params.tag); | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | ||||||
|  |  | ||||||
| 	topics.getTagTids(tag, 0, stop, function(err, tids) { | 	topics.getTagTids(tag, 0, stop, function(err, tids) { | ||||||
| @@ -23,7 +22,7 @@ tagsController.getTag = function(req, res, next) { | |||||||
| 			return res.render('tag', {topics: [], tag: tag}); | 			return res.render('tag', {topics: [], tag: tag}); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		topics.getTopics(tids, uid, function(err, topics) { | 		topics.getTopics(tids, req.uid, function(err, topics) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return next(err); | 				return next(err); | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ topicsController.get = function(req, res, next) { | |||||||
| 	var tid = req.params.topic_id, | 	var tid = req.params.topic_id, | ||||||
| 		page = 1, | 		page = 1, | ||||||
| 		sort = req.query.sort, | 		sort = req.query.sort, | ||||||
| 		uid = req.user ? req.user.uid : 0, |  | ||||||
| 		userPrivileges; | 		userPrivileges; | ||||||
|  |  | ||||||
| 	if (req.params.post_index && !utils.isNumber(req.params.post_index)) { | 	if (req.params.post_index && !utils.isNumber(req.params.post_index)) { | ||||||
| @@ -31,10 +30,10 @@ topicsController.get = function(req, res, next) { | |||||||
| 		function (next) { | 		function (next) { | ||||||
| 			async.parallel({ | 			async.parallel({ | ||||||
| 				privileges: function(next) { | 				privileges: function(next) { | ||||||
| 					privileges.topics.get(tid, uid, next); | 					privileges.topics.get(tid, req.uid, next); | ||||||
| 				}, | 				}, | ||||||
| 				settings: function(next) { | 				settings: function(next) { | ||||||
| 					user.getSettings(uid, next); | 					user.getSettings(req.uid, next); | ||||||
| 				}, | 				}, | ||||||
| 				topic: function(next) { | 				topic: function(next) { | ||||||
| 					topics.getTopicFields(tid, ['slug', 'postcount', 'deleted'], next); | 					topics.getTopicFields(tid, ['slug', 'postcount', 'deleted'], next); | ||||||
| @@ -108,7 +107,7 @@ topicsController.get = function(req, res, next) { | |||||||
| 			var start = (page - 1) * settings.postsPerPage + postIndex, | 			var start = (page - 1) * settings.postsPerPage + postIndex, | ||||||
| 				stop = start + settings.postsPerPage - 1; | 				stop = start + settings.postsPerPage - 1; | ||||||
|  |  | ||||||
| 			topics.getTopicWithPosts(tid, set, uid, start, stop, reverse, function (err, topicData) { | 			topics.getTopicWithPosts(tid, set, req.uid, start, stop, reverse, function (err, topicData) { | ||||||
| 				if (err && err.message === '[[error:no-topic]]' && !topicData) { | 				if (err && err.message === '[[error:no-topic]]' && !topicData) { | ||||||
| 					return helpers.notFound(req, res); | 					return helpers.notFound(req, res); | ||||||
| 				} | 				} | ||||||
| @@ -274,7 +273,6 @@ topicsController.get = function(req, res, next) { | |||||||
|  |  | ||||||
| topicsController.teaser = function(req, res, next) { | topicsController.teaser = function(req, res, next) { | ||||||
| 	var tid = req.params.topic_id; | 	var tid = req.params.topic_id; | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
|  |  | ||||||
| 	if (!utils.isNumber(tid)) { | 	if (!utils.isNumber(tid)) { | ||||||
| 		return next(new Error('[[error:invalid-tid]]')); | 		return next(new Error('[[error:invalid-tid]]')); | ||||||
| @@ -282,7 +280,7 @@ topicsController.teaser = function(req, res, next) { | |||||||
|  |  | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function(next) { | 		function(next) { | ||||||
| 			privileges.topics.can('read', tid, uid, next); | 			privileges.topics.can('read', tid, req.uid, next); | ||||||
| 		}, | 		}, | ||||||
| 		function(canRead, next) { | 		function(canRead, next) { | ||||||
| 			if (!canRead) { | 			if (!canRead) { | ||||||
| @@ -294,7 +292,7 @@ topicsController.teaser = function(req, res, next) { | |||||||
| 			if (!pid) { | 			if (!pid) { | ||||||
| 				return res.status(404).json('not-found'); | 				return res.status(404).json('not-found'); | ||||||
| 			} | 			} | ||||||
| 			posts.getPostSummaryByPids([pid], uid, {stripTags: false}, next); | 			posts.getPostSummaryByPids([pid], req.uid, {stripTags: false}, next); | ||||||
| 		} | 		} | ||||||
| 	], function(err, posts) { | 	], function(err, posts) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
|   | |||||||
| @@ -11,18 +11,17 @@ var async = require('async'), | |||||||
|  |  | ||||||
| usersController.getOnlineUsers = function(req, res, next) { | usersController.getOnlineUsers = function(req, res, next) { | ||||||
| 	var	websockets = require('../socket.io'); | 	var	websockets = require('../socket.io'); | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
|  |  | ||||||
| 	async.parallel({ | 	async.parallel({ | ||||||
| 		users: function(next) { | 		users: function(next) { | ||||||
| 			user.getUsersFromSet('users:online', uid, 0, 49, next); | 			user.getUsersFromSet('users:online', req.uid, 0, 49, next); | ||||||
| 		}, | 		}, | ||||||
| 		count: function(next) { | 		count: function(next) { | ||||||
| 			var now = Date.now(); | 			var now = Date.now(); | ||||||
| 			db.sortedSetCount('users:online', now - 300000, now, next); | 			db.sortedSetCount('users:online', now - 300000, now, next); | ||||||
| 		}, | 		}, | ||||||
| 		isAdministrator: function(next) { | 		isAdministrator: function(next) { | ||||||
| 			user.isAdministrator(uid, next); | 			user.isAdministrator(req.uid, next); | ||||||
| 		} | 		} | ||||||
| 	}, function(err, results) { | 	}, function(err, results) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| @@ -62,9 +61,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| usersController.getUsers = function(set, count, req, res, next) { | usersController.getUsers = function(set, count, req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; | 	getUsersAndCount(set, req.uid, count, function(err, data) { | ||||||
|  |  | ||||||
| 	getUsersAndCount(set, uid, count, function(err, data) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -102,10 +99,9 @@ function getUsersAndCount(set, uid, count, callback) { | |||||||
| } | } | ||||||
|  |  | ||||||
| usersController.getUsersForSearch = function(req, res, next) { | usersController.getUsersForSearch = function(req, res, next) { | ||||||
| 	var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20, | 	var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20; | ||||||
| 		uid = req.user ? req.user.uid : 0; |  | ||||||
|  |  | ||||||
| 	getUsersAndCount('users:joindate', uid, resultsPerPage, function(err, data) { | 	getUsersAndCount('users:joindate', req.uid, resultsPerPage, function(err, data) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -53,19 +53,17 @@ middleware.buildHeader = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| middleware.renderHeader = function(req, res, next) { | middleware.renderHeader = function(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
|  |  | ||||||
| 	var custom_header = { | 	var custom_header = { | ||||||
| 		'plugins': [], | 		'plugins': [], | ||||||
| 		'authentication': [] | 		'authentication': [] | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) { | 	user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		userData.uid = uid; | 		userData.uid = req.uid; | ||||||
| 		userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1; | 		userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1; | ||||||
|  |  | ||||||
| 		async.parallel({ | 		async.parallel({ | ||||||
|   | |||||||
| @@ -124,9 +124,7 @@ middleware.checkGlobalPrivacySettings = function(req, res, next) { | |||||||
|  |  | ||||||
| middleware.checkAccountPermissions = function(req, res, next) { | middleware.checkAccountPermissions = function(req, res, next) { | ||||||
| 	// This middleware ensures that only the requested user and admins can pass | 	// This middleware ensures that only the requested user and admins can pass | ||||||
| 	var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; | 	if (!req.uid) { | ||||||
|  |  | ||||||
| 	if (callerUID === 0) { |  | ||||||
| 		return controllers.helpers.notAllowed(req, res); | 		return controllers.helpers.notAllowed(req, res); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -139,11 +137,11 @@ middleware.checkAccountPermissions = function(req, res, next) { | |||||||
| 			return controllers.helpers.notFound(req, res); | 			return controllers.helpers.notFound(req, res); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (parseInt(uid, 10) === callerUID) { | 		if (parseInt(uid, 10) === req.uid) { | ||||||
| 			return next(); | 			return next(); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		user.isAdministrator(callerUID, function(err, isAdmin) { | 		user.isAdministrator(req.uid, function(err, isAdmin) { | ||||||
| 			if (err || isAdmin) { | 			if (err || isAdmin) { | ||||||
| 				return next(err); | 				return next(err); | ||||||
| 			} | 			} | ||||||
| @@ -201,8 +199,6 @@ middleware.buildHeader = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| middleware.renderHeader = function(req, res, callback) { | middleware.renderHeader = function(req, res, callback) { | ||||||
| 	var uid = req.user ? parseInt(req.user.uid, 10) : 0; |  | ||||||
|  |  | ||||||
| 	navigation.get(function(err, menuItems) { | 	navigation.get(function(err, menuItems) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return callback(err); | 			return callback(err); | ||||||
| @@ -284,8 +280,8 @@ middleware.renderHeader = function(req, res, callback) { | |||||||
| 				next(null, templateValues.useCustomJS ? meta.config.customJS : ''); | 				next(null, templateValues.useCustomJS ? meta.config.customJS : ''); | ||||||
| 			}, | 			}, | ||||||
| 			title: function(next) { | 			title: function(next) { | ||||||
| 				if (uid) { | 				if (req.uid) { | ||||||
| 					user.getSettings(uid, function(err, settings) { | 					user.getSettings(req.uid, function(err, settings) { | ||||||
| 						if (err) { | 						if (err) { | ||||||
| 							return next(err); | 							return next(err); | ||||||
| 						} | 						} | ||||||
| @@ -296,11 +292,11 @@ middleware.renderHeader = function(req, res, callback) { | |||||||
| 				} | 				} | ||||||
| 			}, | 			}, | ||||||
| 			isAdmin: function(next) { | 			isAdmin: function(next) { | ||||||
| 				user.isAdministrator(uid, next); | 				user.isAdministrator(req.uid, next); | ||||||
| 			}, | 			}, | ||||||
| 			user: function(next) { | 			user: function(next) { | ||||||
| 				if (uid) { | 				if (req.uid) { | ||||||
| 					user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'status', 'email:confirmed', 'banned'], next); | 					user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'status', 'email:confirmed', 'banned'], next); | ||||||
| 				} else { | 				} else { | ||||||
| 					next(null, { | 					next(null, { | ||||||
| 						username: '[[global:guest]]', | 						username: '[[global:guest]]', | ||||||
| @@ -527,7 +523,7 @@ middleware.exposeUid = function(req, res, next) { | |||||||
|  |  | ||||||
| 			res.locals.uid = uid; | 			res.locals.uid = uid; | ||||||
| 			next(); | 			next(); | ||||||
| 		}) | 		}); | ||||||
| 	} else { | 	} else { | ||||||
| 		next(); | 		next(); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -35,10 +35,8 @@ function getModerators(req, res, next) { | |||||||
|  |  | ||||||
|  |  | ||||||
| function getRecentPosts(req, res, next) { | function getRecentPosts(req, res, next) { | ||||||
| 	var uid = (req.user) ? req.user.uid : 0; | 	posts.getRecentPosts(req.uid, 0, 19, req.params.term, function (err, data) { | ||||||
|  | 		if (err) { | ||||||
| 	posts.getRecentPosts(uid, 0, 19, req.params.term, function (err, data) { |  | ||||||
| 		if(err) { |  | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,6 +23,11 @@ | |||||||
| 		app.use(passport.initialize()); | 		app.use(passport.initialize()); | ||||||
| 		app.use(passport.session()); | 		app.use(passport.session()); | ||||||
|  |  | ||||||
|  | 		app.use(function(req, res, next) { | ||||||
|  | 			req.uid = req.user ? parseInt(req.user.uid) : 0; | ||||||
|  | 			next(); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
| 		Auth.app = app; | 		Auth.app = app; | ||||||
| 		Auth.middleware = middleware; | 		Auth.middleware = middleware; | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -25,9 +25,7 @@ function hasCategoryPrivileges(req, res, next) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function hasPrivileges(method, id, req, res, next) { | function hasPrivileges(method, id, req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid || 0 : 0; | 	method('read', id, req.uid, function(err, canRead) { | ||||||
|  |  | ||||||
| 	method('read', id, uid, function(err, canRead) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -42,14 +40,13 @@ function hasPrivileges(method, id, req, res, next) { | |||||||
|  |  | ||||||
| function generateForTopic(req, res, next) { | function generateForTopic(req, res, next) { | ||||||
| 	var tid = req.params.topic_id; | 	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) { | 		if (err) { | ||||||
| 			return next(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) { | 			if (err) { | ||||||
| 				return next(err); | 				return next(err); | ||||||
| 			} | 			} | ||||||
| @@ -122,14 +119,14 @@ function generateForUserTopics(req, res, next) { | |||||||
|  |  | ||||||
| function generateForCategory(req, res, next) { | function generateForCategory(req, res, next) { | ||||||
| 	var cid = req.params.category_id; | 	var cid = req.params.category_id; | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	categories.getCategoryById({ | 	categories.getCategoryById({ | ||||||
| 		cid: cid, | 		cid: cid, | ||||||
| 		set: 'cid:' + cid + ':tids', | 		set: 'cid:' + cid + ':tids', | ||||||
| 		reverse: true, | 		reverse: true, | ||||||
| 		start: 0, | 		start: 0, | ||||||
| 		stop: 25, | 		stop: 25, | ||||||
| 		uid: uid | 		uid: req.uid | ||||||
| 	}, function (err, categoryData) { | 	}, function (err, categoryData) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| @@ -159,7 +156,6 @@ function generateForRecent(req, res, next) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function generateForPopular(req, res, next) { | function generateForPopular(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var terms = { | 	var terms = { | ||||||
| 		daily: 'day', | 		daily: 'day', | ||||||
| 		weekly: 'week', | 		weekly: 'week', | ||||||
| @@ -168,7 +164,7 @@ function generateForPopular(req, res, next) { | |||||||
| 	}; | 	}; | ||||||
| 	var term = terms[req.params.term] || 'day'; | 	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) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -196,8 +192,7 @@ function disabledRSS(req, res, next) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function generateForTopics(options, set, req, res, next) { | function generateForTopics(options, set, req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; | 	topics.getTopicsFromSet(set, req.uid, 0, 19, function (err, data) { | ||||||
| 	topics.getTopicsFromSet(set, uid, 0, 19, function (err, data) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -239,8 +234,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function generateForRecentPosts(req, res, next) { | function generateForRecentPosts(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; | 	posts.getRecentPosts(req.uid, 0, 19, 'month', function(err, posts) { | ||||||
| 	posts.getRecentPosts(uid, 0, 19, 'month', function(err, posts) { |  | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
| @@ -257,7 +251,6 @@ function generateForRecentPosts(req, res, next) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function generateForCategoryRecentPosts(req, res, next) { | function generateForCategoryRecentPosts(req, res, next) { | ||||||
| 	var uid = req.user ? req.user.uid : 0; |  | ||||||
| 	var cid = req.params.category_id; | 	var cid = req.params.category_id; | ||||||
|  |  | ||||||
| 	async.parallel({ | 	async.parallel({ | ||||||
| @@ -265,7 +258,7 @@ function generateForCategoryRecentPosts(req, res, next) { | |||||||
| 			categories.getCategoryData(cid, next); | 			categories.getCategoryData(cid, next); | ||||||
| 		}, | 		}, | ||||||
| 		posts: function(next) { | 		posts: function(next) { | ||||||
| 			categories.getRecentReplies(cid, uid, 20, next); | 			categories.getRecentReplies(cid, req.uid, 20, next); | ||||||
| 		} | 		} | ||||||
| 	}, function(err, results) { | 	}, function(err, results) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user