Skip to content

Node.js based forum software built for the modern web

added banned:expire to user hash

barisusakli973e2083299e
diff --git a/src/user.js b/src/user.js
index e4f2eb5f55..d04b7c8cce 100644
--- a/src/user.js
+++ b/src/user.js
@@ -91,7 +91,7 @@ var utils = require('../public/src/utils');
User.getUsers = function(uids, uid, callback) {
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([
function (next) {
@@ -118,6 +118,8 @@ var utils = require('../public/src/utils');
user.joindateISO = utils.toISOString(user.joindate);
user.administrator = results.isAdmin[index];
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.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) {
plugins.registerHook('core', {
hook: 'filter:register.interstitial',
diff --git a/src/user/admin.js b/src/user/admin.js
index cf09c0a4ed..e4384782ee 100644
--- a/src/user/admin.js
+++ b/src/user/admin.js
@@ -71,6 +71,7 @@ module.exports = function(User) {
if (until > 0 && Date.now() < until) {
tasks.push(async.apply(db.sortedSetAdd, 'users:banned:expire', until, uid));
+ tasks.push(async.apply(User.setUserField, uid, 'banned:expire', until));
} else {
until = 0;
}
@@ -91,7 +92,7 @@ module.exports = function(User) {
User.unban = function(uid, callback) {
async.waterfall([
function (next) {
- User.setUserField(uid, 'banned', 0, next);
+ User.setUserFields(uid, {banned: 0, 'banned:expire': 0}, next);
},
function (next) {
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
@@ -103,6 +104,32 @@ module.exports = function(User) {
], 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) {
if (!Array.isArray(uids) || !uids.length) {
return callback();
diff --git a/src/user/data.js b/src/user/data.js
index d5a25bf7b4..6f2a2dd4b7 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -55,18 +55,7 @@ module.exports = function(User) {
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);
- });
- } else {
- modifyUserData(users, fieldsToRemove, callback);
- }
+ modifyUserData(users, fieldsToRemove, callback);
});
};