|
|
|
@ -5,50 +5,65 @@ var user = require('../../user');
|
|
|
|
|
var websockets = require('../index');
|
|
|
|
|
var events = require('../../events');
|
|
|
|
|
|
|
|
|
|
var plugins = require('../../plugins');
|
|
|
|
|
|
|
|
|
|
module.exports = function (SocketUser) {
|
|
|
|
|
|
|
|
|
|
SocketUser.banUsers = function (socket, data, callback) {
|
|
|
|
|
// Backwards compatibility
|
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
|
data = {
|
|
|
|
|
uids: data,
|
|
|
|
|
until: 0,
|
|
|
|
|
reason: ''
|
|
|
|
|
};
|
|
|
|
|
if (!data || !Array.isArray(data.uids)) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleBan(socket.uid, data.uids, function (uid, next) {
|
|
|
|
|
banUser(uid, data.until || 0, data.reason || '', next);
|
|
|
|
|
}, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.each(data.uids, function (uid, next) {
|
|
|
|
|
events.log({
|
|
|
|
|
type: 'user-ban',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
targetUid: uid,
|
|
|
|
|
ip: socket.ip
|
|
|
|
|
}, next);
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
banUser(uid, data.until || 0, data.reason || '', next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
events.log({
|
|
|
|
|
type: 'user-ban',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
targetUid: uid,
|
|
|
|
|
ip: socket.ip
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('action:user.banned', {
|
|
|
|
|
callerUid: socket.uid,
|
|
|
|
|
ip: socket.ip,
|
|
|
|
|
uid: uid,
|
|
|
|
|
until: data.until > 0 ? data.until : undefined
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
}, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.unbanUsers = function (socket, uids, callback) {
|
|
|
|
|
toggleBan(socket.uid, uids, user.unban, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.each(uids, function (uid, next) {
|
|
|
|
|
events.log({
|
|
|
|
|
type: 'user-unban',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
targetUid: uid,
|
|
|
|
|
ip: socket.ip
|
|
|
|
|
}, next);
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
|
|
|
|
toggleBan(socket.uid, uids, function (uid, next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.unban(uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
events.log({
|
|
|
|
|
type: 'user-unban',
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
targetUid: uid,
|
|
|
|
|
ip: socket.ip
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('action:user.unbanned', {
|
|
|
|
|
callerUid: socket.uid,
|
|
|
|
|
ip: socket.ip,
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
}, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function toggleBan(uid, uids, method, callback) {
|
|
|
|
|