mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
added banned:expire to user hash
This commit is contained in:
33
src/user.js
33
src/user.js
@@ -91,7 +91,7 @@ var utils = require('../public/src/utils');
|
|||||||
|
|
||||||
User.getUsers = function(uids, uid, callback) {
|
User.getUsers = function(uids, uid, callback) {
|
||||||
var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'flags',
|
var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'flags',
|
||||||
'banned', 'joindate', 'postcount', 'reputation', 'email:confirmed', 'lastonline'];
|
'banned', 'banned:expire', 'joindate', 'postcount', 'reputation', 'email:confirmed', 'lastonline'];
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -118,6 +118,8 @@ var utils = require('../public/src/utils');
|
|||||||
user.joindateISO = utils.toISOString(user.joindate);
|
user.joindateISO = utils.toISOString(user.joindate);
|
||||||
user.administrator = results.isAdmin[index];
|
user.administrator = results.isAdmin[index];
|
||||||
user.banned = parseInt(user.banned, 10) === 1;
|
user.banned = parseInt(user.banned, 10) === 1;
|
||||||
|
user.banned_until = parseInt(user['banned:expire'], 10) || 0;
|
||||||
|
user.banned_until_readable = user.banned_until ? new Date(user.banned_until).toString() : 'Not Banned';
|
||||||
user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1;
|
user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1;
|
||||||
user.lastonlineISO = utils.toISOString(user.lastonline) || user.joindateISO;
|
user.lastonlineISO = utils.toISOString(user.lastonline) || user.joindateISO;
|
||||||
}
|
}
|
||||||
@@ -258,35 +260,6 @@ var utils = require('../public/src/utils');
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
User.isBanned = function(uid, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
async.apply(User.getUserField, uid, 'banned'),
|
|
||||||
function(banned, next) {
|
|
||||||
banned = parseInt(banned, 10) === 1;
|
|
||||||
if (!banned) {
|
|
||||||
return next(null, banned);
|
|
||||||
} else {
|
|
||||||
// If they are banned, see if the ban has expired
|
|
||||||
db.sortedSetScore('users:banned:expire', uid, function(err, score) {
|
|
||||||
var stillBanned = !score || Date.now() < score;
|
|
||||||
|
|
||||||
if (!stillBanned) {
|
|
||||||
async.parallel([
|
|
||||||
async.apply(db.sortedSetRemove.bind(db), 'users:banned:expire', uid),
|
|
||||||
async.apply(db.sortedSetRemove.bind(db), 'users:banned', uid),
|
|
||||||
async.apply(User.setUserField, uid, 'banned', 0)
|
|
||||||
], function(err) {
|
|
||||||
next(err, false);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next(err, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
User.addInterstitials = function(callback) {
|
User.addInterstitials = function(callback) {
|
||||||
plugins.registerHook('core', {
|
plugins.registerHook('core', {
|
||||||
hook: 'filter:register.interstitial',
|
hook: 'filter:register.interstitial',
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
if (until > 0 && Date.now() < until) {
|
if (until > 0 && Date.now() < until) {
|
||||||
tasks.push(async.apply(db.sortedSetAdd, 'users:banned:expire', until, uid));
|
tasks.push(async.apply(db.sortedSetAdd, 'users:banned:expire', until, uid));
|
||||||
|
tasks.push(async.apply(User.setUserField, uid, 'banned:expire', until));
|
||||||
} else {
|
} else {
|
||||||
until = 0;
|
until = 0;
|
||||||
}
|
}
|
||||||
@@ -91,7 +92,7 @@ module.exports = function(User) {
|
|||||||
User.unban = function(uid, callback) {
|
User.unban = function(uid, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
User.setUserField(uid, 'banned', 0, next);
|
User.setUserFields(uid, {banned: 0, 'banned:expire': 0}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
|
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
|
||||||
@@ -103,6 +104,32 @@ module.exports = function(User) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.isBanned = function(uid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(User.getUserFields, uid, ['banned', 'banned:expire']),
|
||||||
|
function(userData, next) {
|
||||||
|
var banned = parseInt(userData.banned, 10) === 1;
|
||||||
|
if (!banned) {
|
||||||
|
return next(null, banned);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If they are banned, see if the ban has expired
|
||||||
|
var stillBanned = !userData['banned:expire'] || Date.now() < userData['banned:expire'];
|
||||||
|
|
||||||
|
if (stillBanned) {
|
||||||
|
return next(null, true);
|
||||||
|
}
|
||||||
|
async.parallel([
|
||||||
|
async.apply(db.sortedSetRemove.bind(db), 'users:banned:expire', uid),
|
||||||
|
async.apply(db.sortedSetRemove.bind(db), 'users:banned', uid),
|
||||||
|
async.apply(User.setUserFields, uid, {banned:0, 'banned:expire': 0})
|
||||||
|
], function(err) {
|
||||||
|
next(err, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
User.resetFlags = function(uids, callback) {
|
User.resetFlags = function(uids, callback) {
|
||||||
if (!Array.isArray(uids) || !uids.length) {
|
if (!Array.isArray(uids) || !uids.length) {
|
||||||
return callback();
|
return callback();
|
||||||
|
|||||||
@@ -55,19 +55,8 @@ module.exports = function(User) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields.indexOf('banned') !== -1) {
|
|
||||||
// Also retrieve ban expiry for these users
|
|
||||||
db.sortedSetScores('users:banned:expire', uids, function(err, scores) {
|
|
||||||
users.forEach(function(userObj, idx) {
|
|
||||||
userObj.banned_until = scores[idx] || 0;
|
|
||||||
userObj.banned_until_readable = scores[idx] ? new Date(scores[idx]).toString() : 'Not Banned';
|
|
||||||
});
|
|
||||||
modifyUserData(users, fieldsToRemove, callback);
|
modifyUserData(users, fieldsToRemove, callback);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
modifyUserData(users, fieldsToRemove, callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
User.getMultipleUserFields = function(uids, fields, callback) {
|
User.getMultipleUserFields = function(uids, fields, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user