new hook, action:user.delete

v1.18.x
barisusakli 8 years ago
parent 83cd07f830
commit 9e52d5ec04

@ -8,6 +8,7 @@ var groups = require('../../groups');
var user = require('../../user');
var events = require('../../events');
var meta = require('../../meta');
var plugins = require('../../plugins');
var User = {};
@ -177,6 +178,13 @@ function deleteUsers(socket, uids, method, callback) {
uid: socket.uid,
targetUid: uid,
ip: socket.ip
}, next);
},
function (next) {
plugins.fireHook('action:user.delete', {
callerUid: socket.uid,
uid: uid,
ip: socket.ip
});
next();
}

@ -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) {

@ -42,15 +42,7 @@ module.exports = function (User) {
}
async.series(tasks, function (err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.banned', {
uid: uid,
until: until > 0 ? until : undefined
});
callback();
callback(err);
});
};
@ -61,10 +53,6 @@ module.exports = function (User) {
},
function (next) {
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
},
function (next) {
plugins.fireHook('action:user.unbanned', {uid: uid});
next();
}
], callback);
};

@ -88,7 +88,7 @@ module.exports = function (User) {
},
function (next) {
var sets = ['users:joindate', 'users:online'];
if (parseInt(userData.uid) !== 1) {
if (parseInt(userData.uid, 10) !== 1) {
sets.push('users:notvalidated');
}
db.sortedSetsAdd(sets, timestamp, userData.uid, next);

Loading…
Cancel
Save