|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var validator = require('validator');
|
|
|
|
|
|
|
|
|
|
var user = require('../../user');
|
|
|
|
|
var meta = require('../../meta');
|
|
|
|
|
var db = require('../../database');
|
|
|
|
@ -10,6 +12,9 @@ var plugins = require('../../plugins');
|
|
|
|
|
|
|
|
|
|
var usersController = {};
|
|
|
|
|
|
|
|
|
|
var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned',
|
|
|
|
|
'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed'];
|
|
|
|
|
|
|
|
|
|
usersController.search = function(req, res, next) {
|
|
|
|
|
res.render('admin/manage/users', {
|
|
|
|
|
search_display: '',
|
|
|
|
@ -18,67 +23,29 @@ usersController.search = function(req, res, next) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.sortByJoinDate = function(req, res, next) {
|
|
|
|
|
getUsers('users:joindate', 'latest', req, res, next);
|
|
|
|
|
getUsers('users:joindate', 'latest', undefined, undefined, req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.notValidated = function(req, res, next) {
|
|
|
|
|
getUsers('users:notvalidated', 'notvalidated', req, res, next);
|
|
|
|
|
getUsers('users:notvalidated', 'notvalidated', undefined, undefined, req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.noPosts = function(req, res, next) {
|
|
|
|
|
getUsersByScore('users:postcount', 'noposts', 0, 0, req, res, next);
|
|
|
|
|
getUsers('users:postcount', 'noposts', '-inf', 0, req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.flagged = function(req, res, next) {
|
|
|
|
|
getUsersByScore('users:flags', 'mostflags', 1, '+inf', req, res, next);
|
|
|
|
|
getUsers('users:flags', 'mostflags', 1, '+inf', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.inactive = function(req, res, next) {
|
|
|
|
|
var timeRange = 1000 * 60 * 60 * 24 * 30 * (parseInt(req.query.months, 10) || 3);
|
|
|
|
|
var cutoff = Date.now() - timeRange;
|
|
|
|
|
getUsersByScore('users:online', 'inactive', '-inf', cutoff, req, res, next);
|
|
|
|
|
getUsers('users:online', 'inactive', '-inf', cutoff, req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getUsersByScore(set, section, min, max, req, res, callback) {
|
|
|
|
|
var page = parseInt(req.query.page, 10) || 1;
|
|
|
|
|
var resultsPerPage = 25;
|
|
|
|
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
count: function (next) {
|
|
|
|
|
db.sortedSetCount(set, min, max, next);
|
|
|
|
|
},
|
|
|
|
|
uids: function (next) {
|
|
|
|
|
db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next);
|
|
|
|
|
}
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
count = results.count;
|
|
|
|
|
user.getUsers(results.uids, req.uid, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err, users) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
users = users.filter(function(user) {
|
|
|
|
|
return user && parseInt(user.uid, 10);
|
|
|
|
|
});
|
|
|
|
|
var data = {
|
|
|
|
|
users: users,
|
|
|
|
|
page: page,
|
|
|
|
|
pageCount: Math.ceil(count / resultsPerPage)
|
|
|
|
|
};
|
|
|
|
|
data[section] = true;
|
|
|
|
|
render(req, res, data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usersController.banned = function(req, res, next) {
|
|
|
|
|
getUsers('users:banned', 'banned', req, res, next);
|
|
|
|
|
getUsers('users:banned', 'banned', undefined, undefined, req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.registrationQueue = function(req, res, next) {
|
|
|
|
@ -141,18 +108,34 @@ usersController.registrationQueue = function(req, res, next) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getUsers(set, section, req, res, next) {
|
|
|
|
|
function getUsers(set, section, min, max, req, res, next) {
|
|
|
|
|
var page = parseInt(req.query.page, 10) || 1;
|
|
|
|
|
var resultsPerPage = 25;
|
|
|
|
|
var resultsPerPage = 50;
|
|
|
|
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
|
|
|
|
var stop = start + resultsPerPage - 1;
|
|
|
|
|
var byScore = min !== undefined && max !== undefined;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
count: function(next) {
|
|
|
|
|
db.sortedSetCard(set, next);
|
|
|
|
|
if (byScore) {
|
|
|
|
|
db.sortedSetCount(set, min, max, next);
|
|
|
|
|
} else {
|
|
|
|
|
db.sortedSetCard(set, next);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
users: function(next) {
|
|
|
|
|
user.getUsersFromSet(set, req.uid, start, stop, next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
if (byScore) {
|
|
|
|
|
db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next);
|
|
|
|
|
} else {
|
|
|
|
|
user.getUidsFromSet(set, start, stop, next);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
function(uids, next) {
|
|
|
|
|
user.getUsersWithFields(uids, userFields, req.uid, next);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
@ -160,6 +143,7 @@ function getUsers(set, section, req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results.users = results.users.filter(function(user) {
|
|
|
|
|
user.email = validator.escape(String(user.email || ''));
|
|
|
|
|
return user && parseInt(user.uid, 10);
|
|
|
|
|
});
|
|
|
|
|
var data = {
|
|
|
|
|