mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-11-03 20:45:58 +01:00 
			
		
		
		
	style changes
This commit is contained in:
		@@ -10,28 +10,29 @@ var events = require('../../events');
 | 
			
		||||
var meta = require('../../meta');
 | 
			
		||||
var plugins = require('../../plugins');
 | 
			
		||||
 | 
			
		||||
var User = {};
 | 
			
		||||
var User = module.exports;
 | 
			
		||||
 | 
			
		||||
User.makeAdmins = function (socket, uids, callback) {
 | 
			
		||||
	if (!Array.isArray(uids)) {
 | 
			
		||||
		return callback(new Error('[[error:invalid-data]]'));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	user.getUsersFields(uids, ['banned'], function (err, userData) {
 | 
			
		||||
		if (err) {
 | 
			
		||||
			return callback(err);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for (var i = 0; i < userData.length; i += 1) {
 | 
			
		||||
			if (userData[i] && parseInt(userData[i].banned, 10) === 1) {
 | 
			
		||||
				return callback(new Error('[[error:cant-make-banned-users-admin]]'));
 | 
			
		||||
	async.waterfall([
 | 
			
		||||
		function (next) {
 | 
			
		||||
			user.getUsersFields(uids, ['banned'], next);
 | 
			
		||||
		},
 | 
			
		||||
		function (userData, next) {
 | 
			
		||||
			for (var i = 0; i < userData.length; i += 1) {
 | 
			
		||||
				if (userData[i] && parseInt(userData[i].banned, 10) === 1) {
 | 
			
		||||
					return callback(new Error('[[error:cant-make-banned-users-admin]]'));
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		async.each(uids, function (uid, next) {
 | 
			
		||||
			groups.join('administrators', uid, next);
 | 
			
		||||
		}, callback);
 | 
			
		||||
	});
 | 
			
		||||
			async.each(uids, function (uid, next) {
 | 
			
		||||
				groups.join('administrators', uid, next);
 | 
			
		||||
			}, next);
 | 
			
		||||
		},
 | 
			
		||||
	], callback);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
User.removeAdmins = function (socket, uids, callback) {
 | 
			
		||||
@@ -40,17 +41,18 @@ User.removeAdmins = function (socket, uids, callback) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	async.eachSeries(uids, function (uid, next) {
 | 
			
		||||
		groups.getMemberCount('administrators', function (err, count) {
 | 
			
		||||
			if (err) {
 | 
			
		||||
				return next(err);
 | 
			
		||||
			}
 | 
			
		||||
		async.waterfall([
 | 
			
		||||
			function (next) {
 | 
			
		||||
				groups.getMemberCount('administrators', next);
 | 
			
		||||
			},
 | 
			
		||||
			function (count, next) {
 | 
			
		||||
				if (count === 1) {
 | 
			
		||||
					return next(new Error('[[error:cant-remove-last-admin]]'));
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			if (count === 1) {
 | 
			
		||||
				return next(new Error('[[error:cant-remove-last-admin]]'));
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			groups.leave('administrators', uid, next);
 | 
			
		||||
		});
 | 
			
		||||
				groups.leave('administrators', uid, next);
 | 
			
		||||
			},
 | 
			
		||||
		], next);
 | 
			
		||||
	}, callback);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -78,14 +80,16 @@ User.validateEmail = function (socket, uids, callback) {
 | 
			
		||||
		return parseInt(uid, 10);
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	async.each(uids, function (uid, next) {
 | 
			
		||||
		user.setUserField(uid, 'email:confirmed', 1, next);
 | 
			
		||||
	}, function (err) {
 | 
			
		||||
		if (err) {
 | 
			
		||||
			return callback(err);
 | 
			
		||||
		}
 | 
			
		||||
		db.sortedSetRemove('users:notvalidated', uids, callback);
 | 
			
		||||
	});
 | 
			
		||||
	async.waterfall([
 | 
			
		||||
		function (next) {
 | 
			
		||||
			async.each(uids, function (uid, next) {
 | 
			
		||||
				user.setUserField(uid, 'email:confirmed', 1, next);
 | 
			
		||||
			}, next);
 | 
			
		||||
		},
 | 
			
		||||
		function (next) {
 | 
			
		||||
			db.sortedSetRemove('users:notvalidated', uids, next);
 | 
			
		||||
		},
 | 
			
		||||
	], callback);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
User.sendValidationEmail = function (socket, uids, callback) {
 | 
			
		||||
@@ -123,15 +127,17 @@ User.sendPasswordResetEmail = function (socket, uids, callback) {
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	async.each(uids, function (uid, next) {
 | 
			
		||||
		user.getUserFields(uid, ['email', 'username'], function (err, userData) {
 | 
			
		||||
			if (err) {
 | 
			
		||||
				return next(err);
 | 
			
		||||
			}
 | 
			
		||||
			if (!userData.email) {
 | 
			
		||||
				return next(new Error('[[error:user-doesnt-have-email, ' + userData.username + ']]'));
 | 
			
		||||
			}
 | 
			
		||||
			user.reset.send(userData.email, next);
 | 
			
		||||
		});
 | 
			
		||||
		async.waterfall([
 | 
			
		||||
			function (next) {
 | 
			
		||||
				user.getUserFields(uid, ['email', 'username'], next);
 | 
			
		||||
			},
 | 
			
		||||
			function (userData, next) {
 | 
			
		||||
				if (!userData.email) {
 | 
			
		||||
					return next(new Error('[[error:user-doesnt-have-email, ' + userData.username + ']]'));
 | 
			
		||||
				}
 | 
			
		||||
				user.reset.send(userData.email, next);
 | 
			
		||||
			},
 | 
			
		||||
		], next);
 | 
			
		||||
	}, callback);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -257,5 +263,3 @@ User.rejectRegistration = function (socket, data, callback) {
 | 
			
		||||
User.restartJobs = function (socket, data, callback) {
 | 
			
		||||
	user.startJobs(callback);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = User;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user