Baris Soner Usakli 11 years ago
commit 6f94acd0f2

@ -1,6 +1,7 @@
<h1>Users</h1> <h1>Users</h1>
<button id="createUser" class="btn btn-primary">Create User</button> <button id="createUser" class="btn btn-primary">Create User</button>
<a target="_blank" href="/admin/users/csv" class="btn btn-primary">Download CSV</a>
<hr /> <hr />
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li class='active'><a href='{relative_path}/admin/users/latest'>Latest Users</a></li> <li class='active'><a href='{relative_path}/admin/users/latest'>Latest Users</a></li>

@ -159,6 +159,14 @@ var nconf = require('nconf'),
uploadImage(filename, req, res); uploadImage(filename, req, res);
}); });
app.get('/users/csv', function(req, res) {
user.getUsersCSV(function(err, data) {
res.attachment('users.csv');
res.setHeader('Content-Type', 'text/csv');
res.end(data);
});
});
}); });
function uploadImage(filename, req, res) { function uploadImage(filename, req, res) {

@ -409,6 +409,30 @@ var bcrypt = require('bcrypt'),
}); });
}; };
// thanks to @akhoury
User.getUsersCSV = function(callback) {
var csvContent = "";
db.getObjectValues('username:uid', function(err, uids) {
async.each(uids, function(uid, next) {
User.getUserFields(uid, ['email', 'username'], function(err, userData) {
if(err) {
return next(err);
}
csvContent += userData.email+ ',' + userData.username + ',' + uid +'\n';
next();
});
}, function(err) {
if (err) {
throw err;
}
callback(err, csvContent);
});
});
}
User.search = function(username, callback) { User.search = function(username, callback) {
if (!username) { if (!username) {
callback([]); callback([]);

Loading…
Cancel
Save