| 
									
										
										
										
											2014-02-26 21:04:20 -05:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-28 16:52:36 -06:00
										 |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2017-05-26 01:39:40 -06:00
										 |  |  | var _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2013-12-01 16:21:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 15:03:32 -04:00
										 |  |  | var groups = require('../groups'); | 
					
						
							|  |  |  | var plugins = require('../plugins'); | 
					
						
							|  |  |  | var db = require('../database'); | 
					
						
							|  |  |  | var privileges = require('../privileges'); | 
					
						
							|  |  |  | var meta = require('../meta'); | 
					
						
							| 
									
										
										
										
											2013-11-22 14:08:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | var User = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 15:03:32 -04:00
										 |  |  | User.email = require('./email'); | 
					
						
							|  |  |  | User.notifications = require('./notifications'); | 
					
						
							|  |  |  | User.reset = require('./reset'); | 
					
						
							|  |  |  | User.digest = require('./digest'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require('./data')(User); | 
					
						
							|  |  |  | require('./auth')(User); | 
					
						
							|  |  |  | require('./bans')(User); | 
					
						
							|  |  |  | require('./create')(User); | 
					
						
							|  |  |  | require('./posts')(User); | 
					
						
							|  |  |  | require('./topics')(User); | 
					
						
							|  |  |  | require('./categories')(User); | 
					
						
							|  |  |  | require('./follow')(User); | 
					
						
							|  |  |  | require('./profile')(User); | 
					
						
							|  |  |  | require('./admin')(User); | 
					
						
							|  |  |  | require('./delete')(User); | 
					
						
							|  |  |  | require('./settings')(User); | 
					
						
							|  |  |  | require('./search')(User); | 
					
						
							|  |  |  | require('./jobs')(User); | 
					
						
							|  |  |  | require('./picture')(User); | 
					
						
							|  |  |  | require('./approval')(User); | 
					
						
							|  |  |  | require('./invite')(User); | 
					
						
							|  |  |  | require('./password')(User); | 
					
						
							|  |  |  | require('./info')(User); | 
					
						
							|  |  |  | require('./online')(User); | 
					
						
							|  |  |  | require('./blocks')(User); | 
					
						
							|  |  |  | require('./uploads')(User); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | User.getUidsFromSet = function (set, start, stop, callback) { | 
					
						
							|  |  |  | 	if (set === 'users:online') { | 
					
						
							|  |  |  | 		var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1; | 
					
						
							| 
									
										
										
										
											2015-02-12 12:23:13 -05:00
										 |  |  | 		var now = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-10-29 12:18:11 -04:00
										 |  |  | 		db.getSortedSetRevRangeByScore(set, start, count, '+inf', now - (meta.config.onlineCutoff * 60000), callback); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		db.getSortedSetRevRange(set, start, stop, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsersFromSet = function (set, uid, start, stop, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			User.getUidsFromSet(set, start, stop, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (uids, next) { | 
					
						
							|  |  |  | 			User.getUsers(uids, uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsersWithFields = function (uids, fields, uid, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			plugins.fireHook('filter:users.addFields', { fields: fields }, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (data, next) { | 
					
						
							| 
									
										
										
										
											2017-06-25 20:00:05 -04:00
										 |  |  | 			data.fields = _.uniq(data.fields); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			async.parallel({ | 
					
						
							|  |  |  | 				userData: function (next) { | 
					
						
							|  |  |  | 					User.getUsersFields(uids, data.fields, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				isAdmin: function (next) { | 
					
						
							|  |  |  | 					User.isAdministrator(uids, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							|  |  |  | 			results.userData.forEach(function (user, index) { | 
					
						
							|  |  |  | 				if (user) { | 
					
						
							|  |  |  | 					user.administrator = results.isAdmin[index]; | 
					
						
							| 
									
										
										
										
											2017-07-10 00:28:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					if (user.hasOwnProperty('status')) { | 
					
						
							|  |  |  | 						user.status = User.getStatus(user); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-12-16 11:15:43 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 			plugins.fireHook('filter:userlist.get', { users: results.userData, uid: uid }, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (data, next) { | 
					
						
							|  |  |  | 			next(null, data.users); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsers = function (uids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2017-11-08 14:06:52 -05:00
										 |  |  | 	User.getUsersWithFields(uids, [ | 
					
						
							|  |  |  | 		'uid', 'username', 'userslug', 'picture', 'status', | 
					
						
							|  |  |  | 		'postcount', 'reputation', 'email:confirmed', 'lastonline', | 
					
						
							|  |  |  | 		'flags', 'banned', 'banned:expire', 'joindate', | 
					
						
							|  |  |  | 	], uid, callback); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getStatus = function (userData) { | 
					
						
							| 
									
										
										
										
											2018-10-25 17:02:59 -04:00
										 |  |  | 	if (userData.uid <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-26 12:05:34 -04:00
										 |  |  | 		return 'offline'; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-25 17:02:59 -04:00
										 |  |  | 	var isOnline = (Date.now() - userData.lastonline) < 300000; | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 	return isOnline ? (userData.status || 'online') : 'offline'; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.exists = function (uid, callback) { | 
					
						
							| 
									
										
										
										
											2018-10-26 14:31:30 -04:00
										 |  |  | 	db.exists('user:' + uid, callback); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.existsBySlug = function (userslug, callback) { | 
					
						
							|  |  |  | 	User.getUidByUserslug(userslug, function (err, exists) { | 
					
						
							|  |  |  | 		callback(err, !!exists); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUidByUsername = function (username, callback) { | 
					
						
							|  |  |  | 	if (!username) { | 
					
						
							|  |  |  | 		return callback(null, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	db.sortedSetScore('username:uid', username, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUidsByUsernames = function (usernames, callback) { | 
					
						
							|  |  |  | 	db.sortedSetScores('username:uid', usernames, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUidByUserslug = function (userslug, callback) { | 
					
						
							|  |  |  | 	if (!userslug) { | 
					
						
							|  |  |  | 		return callback(null, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	db.sortedSetScore('userslug:uid', userslug, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsernamesByUids = function (uids, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			User.getUsersFields(uids, ['username'], next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (users, next) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			users = users.map(function (user) { | 
					
						
							| 
									
										
										
										
											2014-03-11 03:39:41 -04:00
										 |  |  | 				return user.username; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-07-05 18:19:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 			next(null, users); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsernameByUserslug = function (slug, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			User.getUidByUserslug(slug, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (uid, next) { | 
					
						
							|  |  |  | 			User.getUserField(uid, 'username', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUidByEmail = function (email, callback) { | 
					
						
							|  |  |  | 	db.sortedSetScore('email:uid', email.toLowerCase(), callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUidsByEmails = function (emails, callback) { | 
					
						
							|  |  |  | 	emails = emails.map(function (email) { | 
					
						
							|  |  |  | 		return email && email.toLowerCase(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	db.sortedSetScores('email:uid', emails, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getUsernameByEmail = function (email, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.sortedSetScore('email:uid', email.toLowerCase(), next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (uid, next) { | 
					
						
							|  |  |  | 			User.getUserField(uid, 'username', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isModerator = function (uid, cid, callback) { | 
					
						
							|  |  |  | 	privileges.users.isModerator(uid, cid, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isModeratorOfAnyCategory = function (uid, callback) { | 
					
						
							|  |  |  | 	User.getModeratedCids(uid, function (err, cids) { | 
					
						
							|  |  |  | 		callback(err, Array.isArray(cids) ? !!cids.length : false); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isAdministrator = function (uid, callback) { | 
					
						
							|  |  |  | 	privileges.users.isAdministrator(uid, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isGlobalModerator = function (uid, callback) { | 
					
						
							|  |  |  | 	privileges.users.isGlobalModerator(uid, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 21:35:10 -05:00
										 |  |  | User.getPrivileges = function (uid, callback) { | 
					
						
							|  |  |  | 	async.parallel({ | 
					
						
							|  |  |  | 		isAdmin: async.apply(User.isAdministrator, uid), | 
					
						
							|  |  |  | 		isGlobalModerator: async.apply(User.isGlobalModerator, uid), | 
					
						
							|  |  |  | 		isModeratorOfAnyCategory: async.apply(User.isModeratorOfAnyCategory, uid), | 
					
						
							|  |  |  | 	}, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-07 20:16:59 -05:00
										 |  |  | User.isPrivileged = function (uid, callback) { | 
					
						
							| 
									
										
										
										
											2017-11-15 21:35:10 -05:00
										 |  |  | 	User.getPrivileges(uid, function (err, results) { | 
					
						
							|  |  |  | 		callback(err, results ? (results.isAdmin || results.isGlobalModerator || results.isModeratorOfAnyCategory) : false); | 
					
						
							| 
									
										
										
										
											2017-03-07 20:16:59 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | User.isAdminOrGlobalMod = function (uid, callback) { | 
					
						
							|  |  |  | 	async.parallel({ | 
					
						
							|  |  |  | 		isAdmin: async.apply(User.isAdministrator, uid), | 
					
						
							|  |  |  | 		isGlobalMod: async.apply(User.isGlobalModerator, uid), | 
					
						
							|  |  |  | 	}, function (err, results) { | 
					
						
							|  |  |  | 		callback(err, results ? (results.isAdmin || results.isGlobalMod) : false); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isAdminOrSelf = function (callerUid, uid, callback) { | 
					
						
							|  |  |  | 	isSelfOrMethod(callerUid, uid, User.isAdministrator, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.isAdminOrGlobalModOrSelf = function (callerUid, uid, callback) { | 
					
						
							|  |  |  | 	isSelfOrMethod(callerUid, uid, User.isAdminOrGlobalMod, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 10:18:51 -05:00
										 |  |  | User.isPrivilegedOrSelf = function (callerUid, uid, callback) { | 
					
						
							|  |  |  | 	isSelfOrMethod(callerUid, uid, User.isPrivileged, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | function isSelfOrMethod(callerUid, uid, method, callback) { | 
					
						
							|  |  |  | 	if (parseInt(callerUid, 10) === parseInt(uid, 10)) { | 
					
						
							|  |  |  | 		return callback(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			method(callerUid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (isPass, next) { | 
					
						
							|  |  |  | 			if (!isPass) { | 
					
						
							|  |  |  | 				return next(new Error('[[error:no-privileges]]')); | 
					
						
							| 
									
										
										
										
											2016-09-14 21:06:55 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 			next(); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getAdminsandGlobalMods = function (callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			async.parallel([ | 
					
						
							|  |  |  | 				async.apply(groups.getMembers, 'administrators', 0, -1), | 
					
						
							|  |  |  | 				async.apply(groups.getMembers, 'Global Moderators', 0, -1), | 
					
						
							|  |  |  | 			], next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							| 
									
										
										
										
											2018-06-27 12:15:38 -04:00
										 |  |  | 			User.getUsersData(_.union.apply(_, results), next); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getAdminsandGlobalModsandModerators = function (callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			async.parallel([ | 
					
						
							|  |  |  | 				async.apply(groups.getMembers, 'administrators', 0, -1), | 
					
						
							|  |  |  | 				async.apply(groups.getMembers, 'Global Moderators', 0, -1), | 
					
						
							|  |  |  | 				async.apply(User.getModeratorUids), | 
					
						
							|  |  |  | 			], next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							|  |  |  | 			User.getUsersData(_.union.apply(_, results), next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getModeratorUids = function (callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), | 
					
						
							|  |  |  | 		function (cids, next) { | 
					
						
							| 
									
										
										
										
											2017-07-07 11:56:25 -04:00
										 |  |  | 			var groupNames = cids.reduce(function (memo, cid) { | 
					
						
							|  |  |  | 				memo.push('cid:' + cid + ':privileges:moderate'); | 
					
						
							|  |  |  | 				memo.push('cid:' + cid + ':privileges:groups:moderate'); | 
					
						
							|  |  |  | 				return memo; | 
					
						
							|  |  |  | 			}, []); | 
					
						
							| 
									
										
										
										
											2016-10-13 13:12:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 			groups.getMembersOfGroups(groupNames, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-07-07 11:56:25 -04:00
										 |  |  | 		function (memberSets, next) { | 
					
						
							|  |  |  | 			// Every other set is actually a list of user groups, not uids, so convert those to members
 | 
					
						
							|  |  |  | 			var sets = memberSets.reduce(function (memo, set, idx) { | 
					
						
							|  |  |  | 				if (idx % 2) { | 
					
						
							|  |  |  | 					memo.working.push(set); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					memo.regular.push(set); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return memo; | 
					
						
							|  |  |  | 			}, { working: [], regular: [] }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			groups.getMembersOfGroups(sets.working, function (err, memberSets) { | 
					
						
							| 
									
										
										
										
											2017-07-07 12:10:42 -04:00
										 |  |  | 				next(err, sets.regular.concat(memberSets || [])); | 
					
						
							| 
									
										
										
										
											2017-07-07 11:56:25 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 		function (memberSets, next) { | 
					
						
							|  |  |  | 			next(null, _.union.apply(_, memberSets)); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.getModeratedCids = function (uid, callback) { | 
					
						
							|  |  |  | 	var cids; | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('categories:cid', 0, -1, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (_cids, next) { | 
					
						
							|  |  |  | 			cids = _cids; | 
					
						
							|  |  |  | 			User.isModerator(uid, cids, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (isMods, next) { | 
					
						
							|  |  |  | 			cids = cids.filter(function (cid, index) { | 
					
						
							|  |  |  | 				return cid && isMods[index]; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			next(null, cids); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | User.addInterstitials = function (callback) { | 
					
						
							|  |  |  | 	plugins.registerHook('core', { | 
					
						
							|  |  |  | 		hook: 'filter:register.interstitial', | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 		method: [ | 
					
						
							|  |  |  | 			// GDPR information collection/processing consent + email consent
 | 
					
						
							|  |  |  | 			function (data, callback) { | 
					
						
							| 
									
										
										
										
											2018-10-26 15:20:57 -04:00
										 |  |  | 				if (!meta.config.gdpr_enabled) { | 
					
						
							|  |  |  | 					return setImmediate(callback, null, data); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 				const add = function () { | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 					data.interstitials.push({ | 
					
						
							|  |  |  | 						template: 'partials/gdpr_consent', | 
					
						
							|  |  |  | 						data: { | 
					
						
							|  |  |  | 							digestFrequency: meta.config.dailyDigestFreq, | 
					
						
							|  |  |  | 							digestEnabled: meta.config.dailyDigestFreq !== 'off', | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						callback: function (userData, formData, next) { | 
					
						
							|  |  |  | 							if (formData.gdpr_agree_data === 'on' && formData.gdpr_agree_email === 'on') { | 
					
						
							|  |  |  | 								userData.gdpr_consent = true; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							next(userData.gdpr_consent ? null : new Error('[[register:gdpr_consent_denied]]')); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (!data.userData.gdpr_consent) { | 
					
						
							|  |  |  | 					if (data.userData.uid) { | 
					
						
							|  |  |  | 						db.getObjectField('user:' + data.userData.uid, 'gdpr_consent', function (err, consented) { | 
					
						
							|  |  |  | 							if (err) { | 
					
						
							|  |  |  | 								return callback(err); | 
					
						
							|  |  |  | 							} else if (!parseInt(consented, 10)) { | 
					
						
							|  |  |  | 								add(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2016-10-13 13:12:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 							callback(null, data); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						add(); | 
					
						
							|  |  |  | 						setImmediate(callback, null, data); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					// GDPR consent signed
 | 
					
						
							|  |  |  | 					setImmediate(callback, null, data); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Forum Terms of Use
 | 
					
						
							|  |  |  | 			function (data, callback) { | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 				const add = function () { | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 					data.interstitials.push({ | 
					
						
							|  |  |  | 						template: 'partials/acceptTos', | 
					
						
							|  |  |  | 						data: { | 
					
						
							|  |  |  | 							termsOfUse: meta.config.termsOfUse, | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						callback: function (userData, formData, next) { | 
					
						
							|  |  |  | 							if (formData['agree-terms'] === 'on') { | 
					
						
							|  |  |  | 								userData.acceptTos = true; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							next(userData.acceptTos ? null : new Error('[[register:terms_of_use_error]]')); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (meta.config.termsOfUse && !data.userData.acceptTos) { | 
					
						
							|  |  |  | 					if (data.userData.uid) { | 
					
						
							|  |  |  | 						db.getObjectField('user:' + data.userData.uid, 'acceptTos', function (err, accepted) { | 
					
						
							|  |  |  | 							if (err) { | 
					
						
							|  |  |  | 								return callback(err); | 
					
						
							|  |  |  | 							} else if (!parseInt(accepted, 10)) { | 
					
						
							|  |  |  | 								add(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-02 13:02:07 -04:00
										 |  |  | 							callback(null, data); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						add(); | 
					
						
							|  |  |  | 						setImmediate(callback, null, data); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					// TOS accepted
 | 
					
						
							|  |  |  | 					setImmediate(callback, null, data); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-04-05 16:53:05 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		], | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-06-22 16:47:24 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | 	callback(); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-06-22 16:47:24 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 15:03:32 -04:00
										 |  |  | User.async = require('../promisify')(User); |