|
|
|
@ -8,9 +8,7 @@ var pagination = require('../pagination');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var helpers = require('./helpers');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var usersController = {};
|
|
|
|
|
|
|
|
|
|
var usersController = module.exports;
|
|
|
|
|
|
|
|
|
|
usersController.index = function (req, res, next) {
|
|
|
|
|
var section = req.query.section || 'joindate';
|
|
|
|
@ -33,62 +31,65 @@ usersController.index = function (req, res, next) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.search = function (req, res, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
search: function (next) {
|
|
|
|
|
user.search({
|
|
|
|
|
query: req.query.term,
|
|
|
|
|
searchBy: req.query.searchBy || 'username',
|
|
|
|
|
page: req.query.page || 1,
|
|
|
|
|
sortBy: req.query.sortBy,
|
|
|
|
|
onlineOnly: req.query.onlineOnly === 'true',
|
|
|
|
|
bannedOnly: req.query.bannedOnly === 'true',
|
|
|
|
|
flaggedOnly: req.query.flaggedOnly === 'true',
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
search: function (next) {
|
|
|
|
|
user.search({
|
|
|
|
|
query: req.query.term,
|
|
|
|
|
searchBy: req.query.searchBy || 'username',
|
|
|
|
|
page: req.query.page || 1,
|
|
|
|
|
sortBy: req.query.sortBy,
|
|
|
|
|
onlineOnly: req.query.onlineOnly === 'true',
|
|
|
|
|
bannedOnly: req.query.bannedOnly === 'true',
|
|
|
|
|
flaggedOnly: req.query.flaggedOnly === 'true',
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
isAdminOrGlobalMod: function (next) {
|
|
|
|
|
user.isAdminOrGlobalMod(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
isAdminOrGlobalMod: function (next) {
|
|
|
|
|
user.isAdminOrGlobalMod(req.uid, next);
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var section = req.query.section || 'joindate';
|
|
|
|
|
|
|
|
|
|
results.search.isAdminOrGlobalMod = results.isAdminOrGlobalMod;
|
|
|
|
|
results.search.pagination = pagination.create(req.query.page, results.search.pageCount, req.query);
|
|
|
|
|
results.search['section_' + section] = true;
|
|
|
|
|
render(req, res, results.search, next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var section = req.query.section || 'joindate';
|
|
|
|
|
|
|
|
|
|
results.search.isAdminOrGlobalMod = results.isAdminOrGlobalMod;
|
|
|
|
|
results.search.pagination = pagination.create(req.query.page, results.search.pageCount, req.query);
|
|
|
|
|
results.search['section_' + section] = true;
|
|
|
|
|
render(req, res, results.search, next);
|
|
|
|
|
});
|
|
|
|
|
], next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getOnlineUsers = function (req, res, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function (next) {
|
|
|
|
|
usersController.getUsers('users:online', req.uid, req.query, next);
|
|
|
|
|
},
|
|
|
|
|
guests: function (next) {
|
|
|
|
|
require('../socket.io/admin/rooms').getTotalGuestCount(next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function (next) {
|
|
|
|
|
usersController.getUsers('users:online', req.uid, req.query, next);
|
|
|
|
|
},
|
|
|
|
|
guests: function (next) {
|
|
|
|
|
require('../socket.io/admin/rooms').getTotalGuestCount(next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
var userData = results.users;
|
|
|
|
|
var hiddenCount = 0;
|
|
|
|
|
if (!userData.isAdminOrGlobalMod) {
|
|
|
|
|
userData.users = userData.users.filter(function (user) {
|
|
|
|
|
if (user && user.status === 'offline') {
|
|
|
|
|
hiddenCount += 1;
|
|
|
|
|
}
|
|
|
|
|
return user && user.status !== 'offline';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var userData = results.users;
|
|
|
|
|
var hiddenCount = 0;
|
|
|
|
|
if (!userData.isAdminOrGlobalMod) {
|
|
|
|
|
userData.users = userData.users.filter(function (user) {
|
|
|
|
|
if (user && user.status === 'offline') {
|
|
|
|
|
hiddenCount += 1;
|
|
|
|
|
}
|
|
|
|
|
return user && user.status !== 'offline';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userData.anonymousUserCount = results.guests + hiddenCount;
|
|
|
|
|
userData.anonymousUserCount = results.guests + hiddenCount;
|
|
|
|
|
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
});
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsersSortedByPosts = function (req, res, next) {
|
|
|
|
@ -107,41 +108,36 @@ usersController.getUsersSortedByJoinDate = function (req, res, next) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getBannedUsers = function (req, res, next) {
|
|
|
|
|
usersController.getUsers('users:banned', req.uid, req.query, function (err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!userData.isAdminOrGlobalMod) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
});
|
|
|
|
|
renderIfAdminOrGlobalMod('users:banned', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getFlaggedUsers = function (req, res, next) {
|
|
|
|
|
usersController.getUsers('users:flags', req.uid, req.query, function (err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!userData.isAdminOrGlobalMod) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
});
|
|
|
|
|
renderIfAdminOrGlobalMod('users:flags', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.renderUsersPage = function (set, req, res, next) {
|
|
|
|
|
usersController.getUsers(set, req.uid, req.query, function (err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
function renderIfAdminOrGlobalMod(set, req, res, next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.isAdminOrGlobalMod(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (isAdminOrGlobalMod, next) {
|
|
|
|
|
if (!isAdminOrGlobalMod) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
usersController.renderUsersPage(set, req, res, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
});
|
|
|
|
|
usersController.renderUsersPage = function (set, req, res, next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
usersController.getUsers(set, req.uid, req.query, next);
|
|
|
|
|
},
|
|
|
|
|
function (userData, next) {
|
|
|
|
|
render(req, res, userData, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsers = function (set, uid, query, callback) {
|
|
|
|
@ -169,59 +165,62 @@ usersController.getUsers = function (set, uid, query, callback) {
|
|
|
|
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
|
|
|
|
var stop = start + resultsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdminOrGlobalMod: function (next) {
|
|
|
|
|
user.isAdminOrGlobalMod(uid, next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdminOrGlobalMod: function (next) {
|
|
|
|
|
user.isAdminOrGlobalMod(uid, next);
|
|
|
|
|
},
|
|
|
|
|
usersData: function (next) {
|
|
|
|
|
usersController.getUsersAndCount(set, uid, start, stop, next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
usersData: function (next) {
|
|
|
|
|
usersController.getUsersAndCount(set, uid, start, stop, next);
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var pageCount = Math.ceil(results.usersData.count / resultsPerPage);
|
|
|
|
|
var userData = {
|
|
|
|
|
users: results.usersData.users,
|
|
|
|
|
pagination: pagination.create(page, pageCount, query),
|
|
|
|
|
userCount: results.usersData.count,
|
|
|
|
|
title: setToData[set].title || '[[pages:users/latest]]',
|
|
|
|
|
breadcrumbs: helpers.buildBreadcrumbs(breadcrumbs),
|
|
|
|
|
isAdminOrGlobalMod: results.isAdminOrGlobalMod,
|
|
|
|
|
};
|
|
|
|
|
userData['section_' + (query.section || 'joindate')] = true;
|
|
|
|
|
next(null, userData);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pageCount = Math.ceil(results.usersData.count / resultsPerPage);
|
|
|
|
|
var userData = {
|
|
|
|
|
users: results.usersData.users,
|
|
|
|
|
pagination: pagination.create(page, pageCount, query),
|
|
|
|
|
userCount: results.usersData.count,
|
|
|
|
|
title: setToData[set].title || '[[pages:users/latest]]',
|
|
|
|
|
breadcrumbs: helpers.buildBreadcrumbs(breadcrumbs),
|
|
|
|
|
isAdminOrGlobalMod: results.isAdminOrGlobalMod,
|
|
|
|
|
};
|
|
|
|
|
userData['section_' + (query.section || 'joindate')] = true;
|
|
|
|
|
callback(null, userData);
|
|
|
|
|
});
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.getUsersAndCount = function (set, uid, start, stop, callback) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function (next) {
|
|
|
|
|
user.getUsersFromSet(set, uid, start, stop, next);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function (next) {
|
|
|
|
|
user.getUsersFromSet(set, uid, start, stop, next);
|
|
|
|
|
},
|
|
|
|
|
count: function (next) {
|
|
|
|
|
if (set === 'users:online') {
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
db.sortedSetCount('users:online', now - 300000, '+inf', next);
|
|
|
|
|
} else if (set === 'users:banned') {
|
|
|
|
|
db.sortedSetCard('users:banned', next);
|
|
|
|
|
} else if (set === 'users:flags') {
|
|
|
|
|
db.sortedSetCard('users:flags', next);
|
|
|
|
|
} else {
|
|
|
|
|
db.getObjectField('global', 'userCount', next);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
count: function (next) {
|
|
|
|
|
if (set === 'users:online') {
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
db.sortedSetCount('users:online', now - 300000, '+inf', next);
|
|
|
|
|
} else if (set === 'users:banned') {
|
|
|
|
|
db.sortedSetCard('users:banned', next);
|
|
|
|
|
} else if (set === 'users:flags') {
|
|
|
|
|
db.sortedSetCard('users:flags', next);
|
|
|
|
|
} else {
|
|
|
|
|
db.getObjectField('global', 'userCount', next);
|
|
|
|
|
}
|
|
|
|
|
function (results, next) {
|
|
|
|
|
results.users = results.users.filter(function (user) {
|
|
|
|
|
return user && parseInt(user.uid, 10);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
next(null, results);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
results.users = results.users.filter(function (user) {
|
|
|
|
|
return user && parseInt(user.uid, 10);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, results);
|
|
|
|
|
});
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function render(req, res, data, next) {
|
|
|
|
@ -232,16 +231,15 @@ function render(req, res, data, next) {
|
|
|
|
|
data.adminInviteOnly = registrationType === 'admin-invite-only';
|
|
|
|
|
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
|
|
|
|
|
|
|
|
|
user.getInvitesNumber(req.uid, function (err, numInvites) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.append('X-Total-Count', data.userCount);
|
|
|
|
|
data.invites = numInvites;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
user.getInvitesNumber(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (numInvites) {
|
|
|
|
|
res.append('X-Total-Count', data.userCount);
|
|
|
|
|
data.invites = numInvites;
|
|
|
|
|
|
|
|
|
|
res.render('users', data);
|
|
|
|
|
});
|
|
|
|
|
res.render('users', data);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = usersController;
|
|
|
|
|