|
|
|
@ -1,29 +1,22 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var usersController = {};
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var user = require('../user');
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
|
|
|
|
|
var pagination = require('../pagination');
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var helpers = require('./helpers');
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
validator = require('validator'),
|
|
|
|
|
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
categories = require('../categories'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
pagination = require('../pagination'),
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
|
db = require('../database'),
|
|
|
|
|
helpers = require('./helpers');
|
|
|
|
|
var usersController = {};
|
|
|
|
|
|
|
|
|
|
usersController.getOnlineUsers = function(req, res, next) {
|
|
|
|
|
var websockets = require('../socket.io');
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function(next) {
|
|
|
|
|
user.getUsersFromSet('users:online', req.uid, 0, 49, next);
|
|
|
|
|
},
|
|
|
|
|
count: function(next) {
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
db.sortedSetCount('users:online', now - 300000, now, next);
|
|
|
|
|
userData: function(next) {
|
|
|
|
|
usersController.getUsers('users:online', req.uid, req.query.page, next);
|
|
|
|
|
},
|
|
|
|
|
isAdministrator: function(next) {
|
|
|
|
|
user.isAdministrator(req.uid, next);
|
|
|
|
@ -34,50 +27,54 @@ usersController.getOnlineUsers = function(req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.isAdministrator) {
|
|
|
|
|
results.users = results.users.filter(function(user) {
|
|
|
|
|
results.userData.users = results.userData.users.filter(function(user) {
|
|
|
|
|
return user && user.status !== 'offline';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userData = {
|
|
|
|
|
'route_users:online': true,
|
|
|
|
|
loadmore_display: results.count > 50 ? 'block' : 'hide',
|
|
|
|
|
users: results.users,
|
|
|
|
|
anonymousUserCount: websockets.getOnlineAnonCount(),
|
|
|
|
|
title: '[[pages:users/online]]',
|
|
|
|
|
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:users]]', url: '/users'}, {text: '[[global:online]]'}])
|
|
|
|
|
};
|
|
|
|
|
results.userData.anonymousUserCount = require('../socket.io').getOnlineAnonCount();
|
|
|
|
|
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
render(req, res, results.userData, next);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsersSortedByPosts = function(req, res, next) {
|
|
|
|
|
usersController.getUsers('users:postcount', 0, 49, req, res, next);
|
|
|
|
|
usersController.renderUsersPage('users:postcount', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsersSortedByReputation = function(req, res, next) {
|
|
|
|
|
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
usersController.getUsers('users:reputation', 0, 49, req, res, next);
|
|
|
|
|
usersController.renderUsersPage('users:reputation', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsersSortedByJoinDate = function(req, res, next) {
|
|
|
|
|
usersController.getUsers('users:joindate', 0, 49, req, res, next);
|
|
|
|
|
usersController.renderUsersPage('users:joindate', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsers = function(set, start, stop, req, res, next) {
|
|
|
|
|
usersController.renderUsersPage = function(set, req, res, next) {
|
|
|
|
|
usersController.getUsers(set, req.uid, req.query.page, function(err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsers = function(set, uid, page, callback) {
|
|
|
|
|
var setToTitles = {
|
|
|
|
|
'users:postcount': '[[pages:users/sort-posts]]',
|
|
|
|
|
'users:reputation': '[[pages:users/sort-reputation]]',
|
|
|
|
|
'users:joindate': '[[pages:users/latest]]'
|
|
|
|
|
'users:joindate': '[[pages:users/latest]]',
|
|
|
|
|
'users:online': '[[pages:users/online]]'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var setToCrumbs = {
|
|
|
|
|
'users:postcount': '[[users:top_posters]]',
|
|
|
|
|
'users:reputation': '[[users:most_reputation]]',
|
|
|
|
|
'users:joindate': '[[global:users]]'
|
|
|
|
|
'users:joindate': '[[global:users]]',
|
|
|
|
|
'usesr:online': '[[global:online]]'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var breadcrumbs = [{text: setToCrumbs[set]}];
|
|
|
|
@ -86,21 +83,26 @@ usersController.getUsers = function(set, start, stop, req, res, next) {
|
|
|
|
|
breadcrumbs.unshift({text: '[[global:users]]', url: '/users'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usersController.getUsersAndCount(set, req.uid, start, stop, function(err, data) {
|
|
|
|
|
page = parseInt(page, 10) || 1;
|
|
|
|
|
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
|
|
|
|
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
|
|
|
|
var stop = start + resultsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
usersController.getUsersAndCount(set, uid, start, stop, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pageCount = Math.ceil(data.count / (parseInt(meta.config.userSearchResultsPerPage, 10) || 20));
|
|
|
|
|
var pageCount = Math.ceil(data.count / resultsPerPage);
|
|
|
|
|
var userData = {
|
|
|
|
|
loadmore_display: data.count > (stop - start + 1) ? 'block' : 'hide',
|
|
|
|
|
users: data.users,
|
|
|
|
|
pagination: pagination.create(1, pageCount),
|
|
|
|
|
pagination: pagination.create(page, pageCount),
|
|
|
|
|
title: setToTitles[set] || '[[pages:users/latest]]',
|
|
|
|
|
breadcrumbs: helpers.buildBreadcrumbs(breadcrumbs)
|
|
|
|
|
};
|
|
|
|
|
userData['route_' + set] = true;
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
callback(null, userData);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -110,7 +112,12 @@ usersController.getUsersAndCount = function(set, uid, start, stop, callback) {
|
|
|
|
|
user.getUsersFromSet(set, uid, start, stop, next);
|
|
|
|
|
},
|
|
|
|
|
count: function(next) {
|
|
|
|
|
db.getObjectField('global', 'userCount', next);
|
|
|
|
|
if (set === 'users:online') {
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
db.sortedSetCount('users:online', now - 300000, now, next);
|
|
|
|
|
} else {
|
|
|
|
|
db.getObjectField('global', 'userCount', next);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
@ -149,6 +156,4 @@ function render(req, res, data, next) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = usersController;
|
|
|
|
|