mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	feat: async/await controllers/accounts
This commit is contained in:
		| @@ -1,45 +1,29 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| var async = require('async'); | const user = require('../../user'); | ||||||
|  | const categories = require('../../categories'); | ||||||
|  | const accountHelpers = require('./helpers'); | ||||||
|  |  | ||||||
| var user = require('../../user'); | const categoriesController = module.exports; | ||||||
| var categories = require('../../categories'); |  | ||||||
| var accountHelpers = require('./helpers'); |  | ||||||
|  |  | ||||||
| var categoriesController = module.exports; | categoriesController.get = async function (req, res, next) { | ||||||
|  | 	const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid); | ||||||
|  | 	if (!userData) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  | 	const [states, categoriesData] = await Promise.all([ | ||||||
|  | 		user.getCategoryWatchState(userData.uid), | ||||||
|  | 		categories.buildForSelect(userData.uid, 'find'), | ||||||
|  | 	]); | ||||||
|  |  | ||||||
| categoriesController.get = function (req, res, callback) { | 	categoriesData.forEach(function (category) { | ||||||
| 	var userData; | 		if (category) { | ||||||
| 	async.waterfall([ | 			category.isIgnored = states[category.cid] === categories.watchStates.ignoring; | ||||||
| 		function (next) { | 			category.isWatched = states[category.cid] === categories.watchStates.watching; | ||||||
| 			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); | 			category.isNotWatched = states[category.cid] === categories.watchStates.notwatching; | ||||||
| 		}, | 		} | ||||||
| 		function (_userData, next) { | 	}); | ||||||
| 			userData = _userData; | 	userData.categories = categoriesData; | ||||||
| 			if (!userData) { | 	userData.title = '[[pages:account/watched_categories, ' + userData.username + ']]'; | ||||||
| 				return callback(); | 	res.render('account/categories', userData); | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			async.parallel({ |  | ||||||
| 				states: function (next) { |  | ||||||
| 					user.getCategoryWatchState(userData.uid, next); |  | ||||||
| 				}, |  | ||||||
| 				categories: function (next) { |  | ||||||
| 					categories.buildForSelect(userData.uid, 'find', next); |  | ||||||
| 				}, |  | ||||||
| 			}, next); |  | ||||||
| 		}, |  | ||||||
| 		function (results) { |  | ||||||
| 			results.categories.forEach(function (category) { |  | ||||||
| 				if (category) { |  | ||||||
| 					category.isIgnored = results.states[category.cid] === categories.watchStates.ignoring; |  | ||||||
| 					category.isWatched = results.states[category.cid] === categories.watchStates.watching; |  | ||||||
| 					category.isNotWatched = results.states[category.cid] === categories.watchStates.notwatching; |  | ||||||
| 				} |  | ||||||
| 			}); |  | ||||||
| 			userData.categories = results.categories; |  | ||||||
| 			userData.title = '[[pages:account/watched_categories, ' + userData.username + ']]'; |  | ||||||
| 			res.render('account/categories', userData); |  | ||||||
| 		}, |  | ||||||
| 	], callback); |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,85 +1,62 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| var async = require('async'); | const messaging = require('../../messaging'); | ||||||
|  | const meta = require('../../meta'); | ||||||
|  | const user = require('../../user'); | ||||||
|  | const privileges = require('../../privileges'); | ||||||
|  | const helpers = require('../helpers'); | ||||||
|  |  | ||||||
| var messaging = require('../../messaging'); | const chatsController = module.exports; | ||||||
| var meta = require('../../meta'); |  | ||||||
| var user = require('../../user'); |  | ||||||
| var privileges = require('../../privileges'); |  | ||||||
| var helpers = require('../helpers'); |  | ||||||
|  |  | ||||||
| var chatsController = module.exports; | chatsController.get = async function (req, res, next) { | ||||||
|  |  | ||||||
| chatsController.get = function (req, res, callback) { |  | ||||||
| 	if (meta.config.disableChat) { | 	if (meta.config.disableChat) { | ||||||
| 		return callback(); | 		return next(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var uid; | 	const uid = await user.getUidByUserslug(req.params.userslug); | ||||||
| 	var recentChats; | 	if (!uid) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  | 	const canChat = await privileges.global.can('chat', req.uid); | ||||||
|  | 	if (!canChat) { | ||||||
|  | 		return next(new Error('[[error:no-privileges]]')); | ||||||
|  | 	} | ||||||
|  | 	const recentChats = await messaging.getRecentChats(req.uid, uid, 0, 19); | ||||||
|  | 	if (!recentChats) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	if (!req.params.roomid) { | ||||||
| 		function (next) { | 		return res.render('chats', { | ||||||
| 			user.getUidByUserslug(req.params.userslug, next); | 			rooms: recentChats.rooms, | ||||||
| 		}, | 			uid: uid, | ||||||
| 		function (_uid, next) { | 			userslug: req.params.userslug, | ||||||
| 			uid = _uid; | 			nextStart: recentChats.nextStart, | ||||||
| 			if (!uid) { | 			allowed: true, | ||||||
| 				return callback(); | 			title: '[[pages:chats]]', | ||||||
| 			} | 		}); | ||||||
| 			privileges.global.can('chat', req.uid, next); | 	} | ||||||
| 		}, | 	const room = await messaging.loadRoom(req.uid, { uid: uid, roomId: req.params.roomid }); | ||||||
| 		function (canChat, next) { | 	if (!room) { | ||||||
| 			if (!canChat) { | 		return next(); | ||||||
| 				return next(new Error('[[error:no-privileges]]')); | 	} | ||||||
| 			} |  | ||||||
| 			messaging.getRecentChats(req.uid, uid, 0, 19, next); | 	room.rooms = recentChats.rooms; | ||||||
| 		}, | 	room.nextStart = recentChats.nextStart; | ||||||
| 		function (_recentChats, next) { | 	room.title = room.roomName || room.usernames || '[[pages:chats]]'; | ||||||
| 			recentChats = _recentChats; | 	room.uid = uid; | ||||||
| 			if (!recentChats) { | 	room.userslug = req.params.userslug; | ||||||
| 				return callback(); | 	res.render('chats', room); | ||||||
| 			} |  | ||||||
| 			if (!req.params.roomid) { |  | ||||||
| 				return res.render('chats', { |  | ||||||
| 					rooms: recentChats.rooms, |  | ||||||
| 					uid: uid, |  | ||||||
| 					userslug: req.params.userslug, |  | ||||||
| 					nextStart: recentChats.nextStart, |  | ||||||
| 					allowed: true, |  | ||||||
| 					title: '[[pages:chats]]', |  | ||||||
| 				}); |  | ||||||
| 			} |  | ||||||
| 			messaging.loadRoom(req.uid, { uid: uid, roomId: req.params.roomid }, next); |  | ||||||
| 		}, |  | ||||||
| 		function (room) { |  | ||||||
| 			if (!room) { |  | ||||||
| 				return callback(); |  | ||||||
| 			} |  | ||||||
| 			room.rooms = recentChats.rooms; |  | ||||||
| 			room.nextStart = recentChats.nextStart; |  | ||||||
| 			room.title = room.roomName || room.usernames || '[[pages:chats]]'; |  | ||||||
| 			room.uid = uid; |  | ||||||
| 			room.userslug = req.params.userslug; |  | ||||||
| 			res.render('chats', room); |  | ||||||
| 		}, |  | ||||||
| 	], callback); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| chatsController.redirectToChat = function (req, res, next) { | chatsController.redirectToChat = async function (req, res, next) { | ||||||
| 	var roomid = parseInt(req.params.roomid, 10); |  | ||||||
| 	if (!req.loggedIn) { | 	if (!req.loggedIn) { | ||||||
| 		return next(); | 		return next(); | ||||||
| 	} | 	} | ||||||
| 	async.waterfall([ | 	const userslug = await user.getUserField(req.uid, 'userslug'); | ||||||
| 		function (next) { | 	if (!userslug) { | ||||||
| 			user.getUserField(req.uid, 'userslug', next); | 		return next(); | ||||||
| 		}, | 	} | ||||||
| 		function (userslug, next) { | 	const roomid = parseInt(req.params.roomid, 10); | ||||||
| 			if (!userslug) { | 	helpers.redirect(res, '/user/' + userslug + '/chats' + (roomid ? '/' + roomid : '')); | ||||||
| 				return next(); |  | ||||||
| 			} |  | ||||||
| 			helpers.redirect(res, '/user/' + userslug + '/chats' + (roomid ? '/' + roomid : '')); |  | ||||||
| 		}, |  | ||||||
| 	], next); |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,46 +1,30 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| var async = require('async'); | const db = require('../../database'); | ||||||
|  | const meta = require('../../meta'); | ||||||
|  | const helpers = require('../helpers'); | ||||||
|  | const accountHelpers = require('./helpers'); | ||||||
|  |  | ||||||
| var db = require('../../database'); | const consentController = module.exports; | ||||||
| var meta = require('../../meta'); |  | ||||||
| var helpers = require('../helpers'); |  | ||||||
| var accountHelpers = require('./helpers'); |  | ||||||
|  |  | ||||||
| var consentController = module.exports; | consentController.get = async function (req, res, next) { | ||||||
|  |  | ||||||
| consentController.get = function (req, res, next) { |  | ||||||
| 	if (!meta.config.gdpr_enabled) { | 	if (!meta.config.gdpr_enabled) { | ||||||
| 		// GDPR disabled |  | ||||||
| 		return next(); | 		return next(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var userData; | 	const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid); | ||||||
|  | 	if (!userData) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  | 	const consented = await db.getObjectField('user:' + userData.uid, 'gdpr_consent'); | ||||||
|  | 	userData.gdpr_consent = parseInt(consented, 10) === 1; | ||||||
|  | 	userData.digest = { | ||||||
|  | 		frequency: meta.config.dailyDigestFreq, | ||||||
|  | 		enabled: meta.config.dailyDigestFreq !== 'off', | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	userData.title = '[[user:consent.title]]'; | ||||||
| 		function (next) { | 	userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:consent.title]]' }]); | ||||||
| 			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); |  | ||||||
| 		}, |  | ||||||
| 		function (_userData, next) { |  | ||||||
| 			userData = _userData; |  | ||||||
| 			if (!userData) { |  | ||||||
| 				return next(); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			// Direct database call is used here because `gdpr_consent` is a protected user field and is automatically scrubbed from standard user data retrieval calls | 	res.render('account/consent', userData); | ||||||
| 			db.getObjectField('user:' + userData.uid, 'gdpr_consent', next); |  | ||||||
| 		}, |  | ||||||
| 		function (consented) { |  | ||||||
| 			userData.gdpr_consent = parseInt(consented, 10) === 1; |  | ||||||
| 			userData.digest = { |  | ||||||
| 				frequency: meta.config.dailyDigestFreq, |  | ||||||
| 				enabled: meta.config.dailyDigestFreq !== 'off', |  | ||||||
| 			}; |  | ||||||
|  |  | ||||||
| 			userData.title = '[[user:consent.title]]'; |  | ||||||
| 			userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:consent.title]]' }]); |  | ||||||
|  |  | ||||||
| 			res.render('account/consent', userData); |  | ||||||
| 		}, |  | ||||||
| 	], next); |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,51 +1,41 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| var async = require('async'); | const user = require('../../user'); | ||||||
|  | const helpers = require('../helpers'); | ||||||
|  | const accountHelpers = require('./helpers'); | ||||||
|  | const pagination = require('../../pagination'); | ||||||
|  |  | ||||||
| var user = require('../../user'); | const followController = module.exports; | ||||||
| var helpers = require('../helpers'); |  | ||||||
| var accountHelpers = require('./helpers'); |  | ||||||
| var pagination = require('../../pagination'); |  | ||||||
|  |  | ||||||
| var followController = module.exports; | followController.getFollowing = async function (req, res, next) { | ||||||
|  | 	await getFollow('account/following', 'following', req, res, next); | ||||||
| followController.getFollowing = function (req, res, next) { |  | ||||||
| 	getFollow('account/following', 'following', req, res, next); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| followController.getFollowers = function (req, res, next) { | followController.getFollowers = async function (req, res, next) { | ||||||
| 	getFollow('account/followers', 'followers', req, res, next); | 	await getFollow('account/followers', 'followers', req, res, next); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function getFollow(tpl, name, req, res, callback) { | async function getFollow(tpl, name, req, res, next) { | ||||||
| 	var userData; | 	const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid); | ||||||
|  | 	if (!userData) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	var page = parseInt(req.query.page, 10) || 1; | 	const page = parseInt(req.query.page, 10) || 1; | ||||||
| 	var resultsPerPage = 50; | 	const resultsPerPage = 50; | ||||||
| 	var start = Math.max(0, page - 1) * resultsPerPage; | 	const start = Math.max(0, page - 1) * resultsPerPage; | ||||||
| 	var stop = start + resultsPerPage - 1; | 	const stop = start + resultsPerPage - 1; | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	userData.title = '[[pages:' + tpl + ', ' + userData.username + ']]'; | ||||||
| 		function (next) { |  | ||||||
| 			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); |  | ||||||
| 		}, |  | ||||||
| 		function (data, next) { |  | ||||||
| 			userData = data; |  | ||||||
| 			if (!userData) { |  | ||||||
| 				return callback(); |  | ||||||
| 			} |  | ||||||
| 			var method = name === 'following' ? 'getFollowing' : 'getFollowers'; |  | ||||||
| 			user[method](userData.uid, start, stop, next); |  | ||||||
| 		}, |  | ||||||
| 		function (users) { |  | ||||||
| 			userData.users = users; |  | ||||||
| 			userData.title = '[[pages:' + tpl + ', ' + userData.username + ']]'; |  | ||||||
| 			var count = name === 'following' ? userData.followingCount : userData.followerCount; |  | ||||||
| 			var pageCount = Math.ceil(count / resultsPerPage); |  | ||||||
| 			userData.pagination = pagination.create(page, pageCount); |  | ||||||
| 			userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:' + name + ']]' }]); |  | ||||||
|  |  | ||||||
| 			res.render(tpl, userData); | 	const method = name === 'following' ? 'getFollowing' : 'getFollowers'; | ||||||
| 		}, | 	userData.users = await user[method](userData.uid, start, stop); | ||||||
| 	], callback); |  | ||||||
|  | 	const count = name === 'following' ? userData.followingCount : userData.followerCount; | ||||||
|  | 	const pageCount = Math.ceil(count / resultsPerPage); | ||||||
|  | 	userData.pagination = pagination.create(page, pageCount); | ||||||
|  |  | ||||||
|  | 	userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:' + name + ']]' }]); | ||||||
|  |  | ||||||
|  | 	res.render(tpl, userData); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,43 +1,25 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
|  | const groups = require('../../groups'); | ||||||
|  | const helpers = require('../helpers'); | ||||||
|  | const accountHelpers = require('./helpers'); | ||||||
|  |  | ||||||
| var async = require('async'); | const groupsController = module.exports; | ||||||
|  |  | ||||||
| var groups = require('../../groups'); | groupsController.get = async function (req, res, next) { | ||||||
| var helpers = require('../helpers'); | 	const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid); | ||||||
| var accountHelpers = require('./helpers'); | 	if (!userData) { | ||||||
|  | 		return next(); | ||||||
| var groupsController = module.exports; | 	} | ||||||
|  | 	let groupsData = await groups.getUserGroups([userData.uid]); | ||||||
| groupsController.get = function (req, res, callback) { | 	groupsData = groupsData[0]; | ||||||
| 	var userData; | 	const groupNames = groupsData.filter(Boolean).map(group => group.name); | ||||||
| 	var groupsData; | 	const members = await groups.getMemberUsers(groupNames, 0, 3); | ||||||
| 	async.waterfall([ | 	groupsData.forEach(function (group, index) { | ||||||
| 		function (next) { | 		group.members = members[index]; | ||||||
| 			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); | 	}); | ||||||
| 		}, | 	userData.groups = groupsData; | ||||||
| 		function (_userData, next) { | 	userData.title = '[[pages:account/groups, ' + userData.username + ']]'; | ||||||
| 			userData = _userData; | 	userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:header.groups]]' }]); | ||||||
| 			if (!userData) { | 	res.render('account/groups', userData); | ||||||
| 				return callback(); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			groups.getUserGroups([userData.uid], next); |  | ||||||
| 		}, |  | ||||||
| 		function (_groupsData, next) { |  | ||||||
| 			groupsData = _groupsData[0]; |  | ||||||
| 			const groupNames = groupsData.filter(Boolean).map(group => group.name); |  | ||||||
|  |  | ||||||
| 			groups.getMemberUsers(groupNames, 0, 3, next); |  | ||||||
| 		}, |  | ||||||
| 		function (members) { |  | ||||||
| 			groupsData.forEach(function (group, index) { |  | ||||||
| 				group.members = members[index]; |  | ||||||
| 			}); |  | ||||||
| 			userData.groups = groupsData; |  | ||||||
| 			userData.title = '[[pages:account/groups, ' + userData.username + ']]'; |  | ||||||
| 			userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:header.groups]]' }]); |  | ||||||
| 			res.render('account/groups', userData); |  | ||||||
| 		}, |  | ||||||
| 	], callback); |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,67 +1,54 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| var async = require('async'); | const db = require('../../database'); | ||||||
|  | const user = require('../../user'); | ||||||
|  | const helpers = require('../helpers'); | ||||||
|  | const accountHelpers = require('./helpers'); | ||||||
|  | const pagination = require('../../pagination'); | ||||||
|  |  | ||||||
| var db = require('../../database'); | const infoController = module.exports; | ||||||
| var user = require('../../user'); |  | ||||||
| var helpers = require('../helpers'); |  | ||||||
| var accountHelpers = require('./helpers'); |  | ||||||
| var pagination = require('../../pagination'); |  | ||||||
|  |  | ||||||
| var infoController = module.exports; | infoController.get = async function (req, res, next) { | ||||||
|  | 	const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid); | ||||||
|  | 	if (!userData) { | ||||||
|  | 		return next(); | ||||||
|  | 	} | ||||||
|  | 	const page = Math.max(1, req.query.page || 1); | ||||||
|  | 	const itemsPerPage = 10; | ||||||
|  | 	const start = (page - 1) * itemsPerPage; | ||||||
|  | 	const stop = start + itemsPerPage - 1; | ||||||
|  |  | ||||||
| infoController.get = function (req, res, callback) { | 	const [history, sessions, usernames, emails, notes] = await Promise.all([ | ||||||
| 	var userData; | 		user.getModerationHistory(userData.uid), | ||||||
| 	var page = Math.max(1, req.query.page || 1); | 		user.auth.getSessions(userData.uid, req.sessionID), | ||||||
| 	var itemsPerPage = 10; | 		user.getHistory('user:' + userData.uid + ':usernames'), | ||||||
|  | 		user.getHistory('user:' + userData.uid + ':emails'), | ||||||
|  | 		getNotes(userData, start, stop), | ||||||
|  | 	]); | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	userData.history = history; | ||||||
| 		function (next) { | 	userData.sessions = sessions; | ||||||
| 			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); | 	userData.usernames = usernames; | ||||||
| 		}, | 	userData.emails = emails; | ||||||
| 		function (_userData, next) { |  | ||||||
| 			userData = _userData; |  | ||||||
| 			if (!userData) { |  | ||||||
| 				return callback(); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			var start = (page - 1) * itemsPerPage; | 	if (userData.isAdminOrGlobalModeratorOrModerator) { | ||||||
| 			var stop = start + itemsPerPage - 1; | 		userData.moderationNotes = notes.notes; | ||||||
| 			async.parallel({ | 		const pageCount = Math.ceil(notes.count / itemsPerPage); | ||||||
| 				history: async.apply(user.getModerationHistory, userData.uid), | 		userData.pagination = pagination.create(page, pageCount, req.query); | ||||||
| 				sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID), | 	} | ||||||
| 				usernames: async.apply(user.getHistory, 'user:' + userData.uid + ':usernames'), | 	userData.title = '[[pages:account/info]]'; | ||||||
| 				emails: async.apply(user.getHistory, 'user:' + userData.uid + ':emails'), | 	userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:account_info]]' }]); | ||||||
| 				notes: function (next) { |  | ||||||
| 					if (!userData.isAdminOrGlobalModeratorOrModerator) { |  | ||||||
| 						return setImmediate(next); |  | ||||||
| 					} |  | ||||||
| 					async.parallel({ |  | ||||||
| 						notes: function (next) { |  | ||||||
| 							user.getModerationNotes(userData.uid, start, stop, next); |  | ||||||
| 						}, |  | ||||||
| 						count: function (next) { |  | ||||||
| 							db.sortedSetCard('uid:' + userData.uid + ':moderation:notes', next); |  | ||||||
| 						}, |  | ||||||
| 					}, next); |  | ||||||
| 				}, |  | ||||||
| 			}, next); |  | ||||||
| 		}, |  | ||||||
| 		function (data) { |  | ||||||
| 			userData.history = data.history; |  | ||||||
| 			userData.sessions = data.sessions; |  | ||||||
| 			userData.usernames = data.usernames; |  | ||||||
| 			userData.emails = data.emails; |  | ||||||
|  |  | ||||||
| 			if (userData.isAdminOrGlobalModeratorOrModerator) { | 	res.render('account/info', userData); | ||||||
| 				userData.moderationNotes = data.notes.notes; |  | ||||||
| 				var pageCount = Math.ceil(data.notes.count / itemsPerPage); |  | ||||||
| 				userData.pagination = pagination.create(page, pageCount, req.query); |  | ||||||
| 			} |  | ||||||
| 			userData.title = '[[pages:account/info]]'; |  | ||||||
| 			userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:account_info]]' }]); |  | ||||||
|  |  | ||||||
| 			res.render('account/info', userData); |  | ||||||
| 		}, |  | ||||||
| 	], callback); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | async function getNotes(userData, start, stop) { | ||||||
|  | 	if (!userData.isAdminOrGlobalModeratorOrModerator) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	const [notes, count] = await Promise.all([ | ||||||
|  | 		user.getModerationNotes(userData.uid, start, stop), | ||||||
|  | 		db.sortedSetCard('uid:' + userData.uid + ':moderati;on:notes'), | ||||||
|  | 	]); | ||||||
|  | 	return { notes: notes, count: count }; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user