Skip to content

Node.js based forum software built for the modern web

related to #1250

barisusaklifa98da697863
diff --git a/public/src/forum/users.js b/public/src/forum/users.js
index f10c739918..003b795492 100644
--- a/public/src/forum/users.js
+++ b/public/src/forum/users.js
@@ -63,19 +63,20 @@ define(function() {
templates['users'].parse({users:[]});
var html = templates.prepare(templates['users'].blocks['users']).parse({
users: data.users
- }),
- userListEl = $('#users-container');
+ });
- userListEl.html(html);
+ translator.translate(html, function(translated) {
+ $('#users-container').html(translated);
- if (data && data.users.length === 0) {
- $('#user-notfound-notify').html('User not found!');
- $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
- } else {
- $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
- $('#user-notfound-notify').parent().addClass('btn-success label-success');
- }
+ if (data && data.users.length === 0) {
+ $('#user-notfound-notify').html('User not found!');
+ $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
+ } else {
+ $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
+ $('#user-notfound-notify').parent().addClass('btn-success label-success');
+ }
+ });
});
});
}, 500); //replace this with global throttling function/constant
diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js
index 4cf53b79bd..c2bb41fb80 100644
--- a/src/controllers/admin/users.js
+++ b/src/controllers/admin/users.js
@@ -26,7 +26,7 @@ usersController.sortByJoinDate = function(req, res, next) {
};
function getUsers(set, req, res, next) {
- user.getUsers(set, 0, 49, function(err, users) {
+ user.getUsersFromSet(set, 0, 49, function(err, users) {
if (err) {
return next(err);
}
diff --git a/src/controllers/users.js b/src/controllers/users.js
index ed6e10dbb5..4d97298c40 100644
--- a/src/controllers/users.js
+++ b/src/controllers/users.js
@@ -9,7 +9,7 @@ var async = require('async'),
usersController.getOnlineUsers = function(req, res, next) {
var websockets = require('../socket.io');
- user.getUsers('users:online', 0, 49, function (err, data) {
+ user.getUsersFromSet('users:online', 0, 49, function (err, data) {
if(err) {
return next(err);
}
@@ -72,7 +72,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) {
};
function getUsers(set, res, next) {
- user.getUsers(set, 0, 49, function (err, data) {
+ user.getUsersFromSet(set, 0, 49, function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index 6ee6657463..e100226cb4 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -4,6 +4,7 @@ var async = require('async'),
user = require('../user'),
topics = require('../topics'),
utils = require('./../../public/src/utils'),
+ meta = require('../meta'),
SocketUser = {};
SocketUser.exists = function(socket, data, callback) {
@@ -204,6 +205,10 @@ SocketUser.loadMore = function(socket, data, callback) {
return callback(new Error('invalid-data'));
}
+ if (!socket.uid && !!parseInt(meta.config.privateUserInfo, 10)) {
+ return callback(new Error('not-allowed'));
+ }
+
var start = data.after,
end = start + 19;
@@ -231,7 +236,6 @@ SocketUser.loadMore = function(socket, data, callback) {
};
-
SocketUser.setStatus = function(socket, status, callback) {
var server = require('./index');
user.setUserField(socket.uid, 'status', status, function(err) {
diff --git a/src/user.js b/src/user.js
index 936fe8b111..ed84ce8ad3 100644
--- a/src/user.js
+++ b/src/user.js
@@ -142,7 +142,18 @@ var bcrypt = require('bcryptjs'),
db.incrObjectFieldBy('user:' + uid, field, -value, callback);
};
- User.getUsers = function(set, start, stop, callback) {
+ User.getUsersFromSet = function(set, start, stop, callback) {
+ async.waterfall([
+ function(next) {
+ db.getSortedSetRevRange(set, start, stop, next);
+ },
+ function(uids, next) {
+ User.getUsers(uids, next);
+ }
+ ], callback);
+ };
+
+ User.getUsers = function(uids, callback) {
function loadUserInfo(user, callback) {
if (!user) {
return callback(null, user);
@@ -155,13 +166,10 @@ var bcrypt = require('bcryptjs'),
function(isAdmin, next) {
user.status = !user.status ? 'online' : user.status;
user.administrator = isAdmin ? '1':'0';
- if (set === 'users:online') {
- return callback(null, user);
- }
- db.sortedSetScore('users:online', user.uid, next);
+ db.isSortedSetMember('users:online', user.uid, next);
},
- function(score, next) {
- if (!score) {
+ function(isMember, next) {
+ if (!isMember) {
user.status = 'offline';
}
next(null, user);
@@ -169,17 +177,13 @@ var bcrypt = require('bcryptjs'),
], callback);
}
- async.waterfall([
- function(next) {
- db.getSortedSetRevRange(set, start, stop, next);
- },
- function(uids, next) {
- User.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation'], next);
- },
- function(users, next) {
- async.map(users, loadUserInfo, next);
+ User.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation'], function(err, usersData) {
+ if (err) {
+ return callback(err);
}
- ], callback);
+
+ async.map(usersData, loadUserInfo, callback);
+ });
};
User.createGravatarURLFromEmail = function(email) {
diff --git a/src/user/search.js b/src/user/search.js
index 587f175352..a87d75be35 100644
--- a/src/user/search.js
+++ b/src/user/search.js
@@ -31,10 +31,11 @@ module.exports = function(User) {
return usernamesHash[username];
});
- User.getUsersData(uids, function(err, userdata) {
+ User.getUsers(uids, function(err, userdata) {
if (err) {
return callback(err);
}
+
var diff = process.hrtime(start);
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
callback(null, {timing: timing, users: userdata});