WIP temporary bans

v1.18.x
Julian Lam 9 years ago
parent 688028c63b
commit 7da71976cf

@ -37,6 +37,7 @@
"user-banned": "User banned",
"user-too-new": "Sorry, you are required to wait %1 second(s) before making your first post",
"blacklisted-ip": "Sorry, your IP address has been banned from this community. If you feel this is in error, please contact an administrator.",
"ban-expiry-missing": "Please provide an end date for this ban",
"no-category": "Category does not exist",
"no-topic": "Topic does not exist",

@ -7,7 +7,12 @@ var events = require('../../events');
module.exports = function(SocketUser) {
SocketUser.banUsers = function(socket, uids, callback) {
SocketUser.banUsers = function(socket, uids, until, callback) {
if (!callback && typeof until === 'function') {
callback = until;
until = 0;
}
toggleBan(socket.uid, uids, SocketUser.banUser, function(err) {
if (err) {
return callback(err);
@ -45,7 +50,7 @@ module.exports = function(SocketUser) {
], callback);
}
SocketUser.banUser = function(uid, callback) {
SocketUser.banUser = function(uid, until, callback) {
async.waterfall([
function (next) {
user.isAdministrator(uid, next);
@ -54,7 +59,7 @@ module.exports = function(SocketUser) {
if (isAdmin) {
return next(new Error('[[error:cant-ban-other-admins]]'));
}
user.ban(uid, next);
user.ban(uid, until, next);
},
function (next) {
websockets.in('uid_' + uid).emit('event:banned');

@ -52,19 +52,35 @@ module.exports = function(User) {
], callback);
};
User.ban = function(uid, callback) {
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();
User.ban = function(uid, until, callback) {
// "until" (optional) is unix timestamp in milliseconds
if (!callback && typeof until === 'function') {
callback = until;
until = 0;
}
], callback);
until = parseInt(until, 10);
if (isNaN(until)) {
return callback(new Error('[[error:ban-expiry-missing]]'));
}
var tasks = [
async.apply(User.setUserField, uid, 'banned', 1),
async.apply(db.sortedSetAdd, 'users:banned', Date.now(), uid),
];
if (until > 0 && Date.now() < until) {
tasks.push(async.apply(db.sortedSetAdd, 'users:banned:expire', until, uid));
}
async.series(tasks, function (err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.banned', {uid: uid});
callback();
});
};
User.unban = function(uid, callback) {

Loading…
Cancel
Save