From 42cce3771b32354119c3c02c0953ae4e4e9c6fb3 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 11 Dec 2015 15:17:05 +0200 Subject: [PATCH] closes #3846 --- src/user/admin.js | 48 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/user/admin.js b/src/user/admin.js index 95075b88f1..004e048c93 100644 --- a/src/user/admin.js +++ b/src/user/admin.js @@ -1,9 +1,9 @@ 'use strict'; -var async = require('async'), - db = require('./../database'); - +var async = require('async'); +var db = require('../database'); +var plugins = require('../plugins'); module.exports = function(User) { @@ -17,7 +17,7 @@ module.exports = function(User) { User.getIPs = function(uid, stop, callback) { db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop, function(err, ips) { - if(err) { + if (err) { return callback(err); } @@ -31,17 +31,17 @@ module.exports = function(User) { var csvContent = ''; async.waterfall([ - function(next) { + function (next) { db.getSortedSetRangeWithScores('username:uid', 0, -1, next); }, - function(users, next) { + function (users, next) { var uids = users.map(function(user) { return user.score; }); User.getUsersFields(uids, ['uid', 'email', 'username'], next); }, - function(usersData, next) { - usersData.forEach(function(user, index) { + function (usersData, next) { + usersData.forEach(function(user) { if (user) { csvContent += user.email + ',' + user.username + ',' + user.uid + '\n'; } @@ -53,22 +53,34 @@ module.exports = function(User) { }; User.ban = function(uid, callback) { - User.setUserField(uid, 'banned', 1, function(err) { - if (err) { - return callback(err); + async.waterfall([ + function (next) { + User.setUserField(uid, 'banned', 1, next); + }, + function (next) { + db.sortedSetAdd('users:banned', Date.now(), uid, next); + }, + function (next) { + plugins.fireHook('action:user.banned', {uid: uid}); + next(); } - db.sortedSetAdd('users:banned', Date.now(), uid, callback); - }); + ], callback); }; User.unban = function(uid, callback) { db.delete('uid:' + uid + ':flagged_by'); - User.setUserField(uid, 'banned', 0, function(err) { - if (err) { - return callback(err); + async.waterfall([ + function (next) { + User.setUserField(uid, 'banned', 0, next); + }, + function (next) { + db.sortedSetRemove('users:banned', uid, next); + }, + function (next) { + plugins.fireHook('action:user.unbanned', {uid: uid}); + next(); } - db.sortedSetRemove('users:banned', uid, callback); - }); + ], callback); }; User.resetFlags = function(uids, callback) {