mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
feat: #7743 user/admin.js
This commit is contained in:
@@ -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);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user