Skip to content

Node.js based forum software built for the modern web

new hook, action:user.delete

barisusakli9e52d5ec04b1
diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js
index 4a77c224a7..87a4c2d2ae 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -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();
}
diff --git a/src/socket.io/user/ban.js b/src/socket.io/user/ban.js
index cdc1e20e6d..089720c59e 100644
--- a/src/socket.io/user/ban.js
+++ b/src/socket.io/user/ban.js
@@ -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) {
diff --git a/src/user/bans.js b/src/user/bans.js
index a0b81587ee..8667641c46 100644
--- a/src/user/bans.js
+++ b/src/user/bans.js
@@ -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);
};
diff --git a/src/user/create.js b/src/user/create.js
index 46508d1d0b..67d6baf3cd 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -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);