2014-03-12 17:59:29 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
2015-11-27 16:55:31 -07:00
|
|
|
var async = require('async'),
|
|
|
|
|
user = require('../../user'),
|
2014-10-06 13:11:12 -04:00
|
|
|
meta = require('../../meta');
|
2014-03-12 17:59:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var usersController = {};
|
|
|
|
|
|
|
|
|
|
usersController.search = function(req, res, next) {
|
2014-09-28 21:09:40 -04:00
|
|
|
res.render('admin/manage/users', {
|
2014-09-25 15:13:54 -04:00
|
|
|
search_display: '',
|
2014-12-31 17:13:19 -05:00
|
|
|
loadmore_display: 'hide',
|
2014-03-12 17:59:29 -04:00
|
|
|
users: []
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.sortByPosts = function(req, res, next) {
|
2014-03-15 16:28:57 -04:00
|
|
|
getUsers('users:postcount', req, res, next);
|
2014-03-12 17:59:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.sortByReputation = function(req, res, next) {
|
2014-03-15 16:28:57 -04:00
|
|
|
getUsers('users:reputation', req, res, next);
|
2014-03-12 17:59:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
usersController.sortByJoinDate = function(req, res, next) {
|
2014-03-15 16:28:57 -04:00
|
|
|
getUsers('users:joindate', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-03 14:14:41 -04:00
|
|
|
usersController.banned = function(req, res, next) {
|
|
|
|
|
getUsers('users:banned', req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-27 21:26:19 -04:00
|
|
|
usersController.registrationQueue = function(req, res, next) {
|
2015-11-27 16:55:31 -07:00
|
|
|
var invitations;
|
|
|
|
|
async.parallel({
|
|
|
|
|
users: function(next) {
|
|
|
|
|
user.getRegistrationQueue(0, -1, next);
|
|
|
|
|
},
|
|
|
|
|
invites: function(next) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
user.getAllInvites(next);
|
|
|
|
|
},
|
|
|
|
|
function(_invitations, next) {
|
|
|
|
|
invitations = _invitations;
|
|
|
|
|
async.map(invitations, function(invites, next) {
|
|
|
|
|
user.getUserField(invites.uid, 'username', next);
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(usernames, next) {
|
|
|
|
|
invitations.forEach(function(invites, index) {
|
|
|
|
|
invites.username = usernames[index];
|
|
|
|
|
});
|
|
|
|
|
async.map(invitations, function(invites, next) {
|
|
|
|
|
async.map(invites.invitations, user.getUsernameByEmail, next);
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(usernames, next) {
|
|
|
|
|
invitations.forEach(function(invites, index) {
|
|
|
|
|
invites.invitations = invites.invitations.map(function(email, i) {
|
|
|
|
|
return {
|
|
|
|
|
email: email,
|
|
|
|
|
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i]
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
next(null, invitations);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, data) {
|
2015-06-27 21:26:19 -04:00
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
2015-11-27 16:55:31 -07:00
|
|
|
res.render('admin/manage/registration', data);
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-27 21:26:19 -04:00
|
|
|
};
|
|
|
|
|
|
2014-03-15 16:28:57 -04:00
|
|
|
function getUsers(set, req, res, next) {
|
2015-04-01 00:23:57 -04:00
|
|
|
user.getUsersFromSet(set, req.uid, 0, 49, function(err, users) {
|
2014-03-15 16:28:57 -04:00
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
2014-12-29 15:11:52 -05:00
|
|
|
|
|
|
|
|
users = users.filter(function(user) {
|
|
|
|
|
return user && parseInt(user.uid, 10);
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-28 21:09:40 -04:00
|
|
|
res.render('admin/manage/users', {
|
2014-09-25 15:13:54 -04:00
|
|
|
search_display: 'hidden',
|
2014-03-15 16:28:57 -04:00
|
|
|
loadmore_display: 'block',
|
2014-03-12 17:59:29 -04:00
|
|
|
users: users,
|
2015-04-01 00:23:57 -04:00
|
|
|
yourid: req.uid,
|
2014-10-06 13:11:12 -04:00
|
|
|
requireEmailConfirmation: parseInt(meta.config.requireEmailConfirmation, 10) === 1
|
2014-03-12 17:59:29 -04:00
|
|
|
});
|
|
|
|
|
});
|
2014-03-15 16:28:57 -04:00
|
|
|
}
|
2014-03-12 17:59:29 -04:00
|
|
|
|
|
|
|
|
usersController.getCSV = function(req, res, next) {
|
|
|
|
|
user.getUsersCSV(function(err, data) {
|
2014-12-31 17:13:19 -05:00
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
2014-03-12 17:59:29 -04:00
|
|
|
res.attachment('users.csv');
|
|
|
|
|
res.setHeader('Content-Type', 'text/csv');
|
|
|
|
|
res.end(data);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-10 20:31:57 +01:00
|
|
|
module.exports = usersController;
|