feat: #7743 user/admin.js

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 4170abfd6b
commit 2c33595507

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var async = require('async');
var winston = require('winston'); var winston = require('winston');
var validator = require('validator'); var validator = require('validator');
@ -9,9 +8,9 @@ var db = require('../database');
var plugins = require('../plugins'); var plugins = require('../plugins');
module.exports = function (User) { module.exports = function (User) {
User.logIP = function (uid, ip, callback) { User.logIP = async function (uid, ip) {
if (!(parseInt(uid, 10) > 0)) { if (!(parseInt(uid, 10) > 0)) {
return setImmediate(callback); return;
} }
var now = Date.now(); var now = Date.now();
const bulk = [ const bulk = [
@ -20,44 +19,25 @@ module.exports = function (User) {
if (ip) { if (ip) {
bulk.push(['ip:' + ip + ':uid', now, uid]); bulk.push(['ip:' + ip + ':uid', now, uid]);
} }
db.sortedSetAddBulk(bulk, callback); await db.sortedSetAddBulk(bulk);
}; };
User.getIPs = function (uid, stop, callback) { User.getIPs = async function (uid, stop) {
async.waterfall([ const ips = await db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop);
function (next) { return ips.map(ip => validator.escape(String(ip)));
db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop, next);
},
function (ips, next) {
next(null, ips.map(ip => validator.escape(String(ip))));
},
], callback);
}; };
User.getUsersCSV = function (callback) { User.getUsersCSV = async function () {
winston.verbose('[user/getUsersCSV] Compiling User CSV data'); winston.verbose('[user/getUsersCSV] Compiling User CSV data');
var csvContent = ''; var csvContent = '';
var uids; var uids = await db.getSortedSetRange('users:joindate', 0, -1);
async.waterfall([ const data = await plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] });
function (next) { const usersData = await User.getUsersFields(uids, data.fields);
db.getSortedSetRange('users:joindate', 0, -1, next); usersData.forEach(function (user) {
}, if (user) {
function (_uids, next) { csvContent += user.email + ',' + user.username + ',' + user.uid + '\n';
uids = _uids; }
plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] }, next); });
}, return csvContent;
function (data, next) {
User.getUsersFields(uids, data.fields, next);
},
function (usersData, next) {
usersData.forEach(function (user) {
if (user) {
csvContent += user.email + ',' + user.username + ',' + user.uid + '\n';
}
});
next(null, csvContent);
},
], callback);
}; };
}; };

Loading…
Cancel
Save