v1.18.x
barisusakli 10 years ago
parent 09a5d92dba
commit 612aa4e55b

@ -215,13 +215,14 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable)
} }
}); });
$('#search-user-name, #search-user-email').on('keyup', function() { $('#search-user-name, #search-user-email, #search-user-ip').on('keyup', function() {
if (timeoutId !== 0) { if (timeoutId !== 0) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
timeoutId = 0; timeoutId = 0;
} }
var $this = $(this); var $this = $(this);
var type = $this.attr('id') === 'search-user-name' ? 'username' : 'email'; var type = $this.attr('data-search-type');
timeoutId = setTimeout(function() { timeoutId = setTimeout(function() {
$('.fa-spinner').removeClass('hidden'); $('.fa-spinner').removeClass('hidden');

@ -8,7 +8,11 @@ var async = require('async'),
module.exports = function(User) { module.exports = function(User) {
User.logIP = function(uid, ip) { User.logIP = function(uid, ip) {
db.sortedSetAdd('uid:' + uid + ':ip', Date.now(), ip || 'Unknown'); var now = Date.now();
db.sortedSetAdd('uid:' + uid + ':ip', now, ip || 'Unknown');
if (ip) {
db.sortedSetAdd('ip:' + ip + ':uid', now, uid);
}
}; };
User.getIPs = function(uid, end, callback) { User.getIPs = function(uid, end, callback) {

@ -1,7 +1,8 @@
'use strict'; 'use strict';
var db = require('../database'); var async = require('async'),
db = require('../database');
module.exports = function(User) { module.exports = function(User) {
@ -9,14 +10,18 @@ module.exports = function(User) {
if (!query || query.length === 0) { if (!query || query.length === 0) {
return callback(null, {timing:0, users:[]}); return callback(null, {timing:0, users:[]});
} }
var start = process.hrtime();
var set = 'username:uid'; if (type === 'ip') {
return searchByIP(query, callback);
}
var start = process.hrtime();
var key = 'username:uid';
if (type === 'email') { if (type === 'email') {
set = 'email:uid'; key = 'email:uid';
} }
db.getObject(set, function(err, hash) { db.getObject(key, function(err, hash) {
if (err) { if (err) {
return callback(null, {timing: 0, users:[]}); return callback(null, {timing: 0, users:[]});
} }
@ -51,4 +56,21 @@ module.exports = function(User) {
}); });
}); });
}; };
function searchByIP(ip, callback) {
var start = process.hrtime();
async.waterfall([
function(next) {
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next);
},
function(uids, next) {
User.getUsers(uids, next);
},
function(users, next) {
var diff = process.hrtime(start);
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
next(null, {timing: timing, users: users});
}
], callback);
}
}; };

@ -33,10 +33,13 @@
<div class="search {search_display} well"> <div class="search {search_display} well">
<label>By User Name</label> <label>By User Name</label>
<input class="form-control" id="search-user-name" type="text" placeholder="Enter a username to search"/><br /> <input class="form-control" id="search-user-name" data-search-type="username" type="text" placeholder="Enter a username to search"/><br />
<label>By Email </label> <label>By Email </label>
<input class="form-control" id="search-user-email" type="text" placeholder="Enter a email to search"/><br /> <input class="form-control" id="search-user-email" data-search-type="email" type="text" placeholder="Enter a email to search"/><br />
<label>By IP Address </label>
<input class="form-control" id="search-user-ip" data-search-type="ip" type="text" placeholder="Enter an IP Address to search"/><br />
<i class="fa fa-spinner fa-spin hidden"></i> <i class="fa fa-spinner fa-spin hidden"></i>
<span id="user-notfound-notify" class="label label-danger hide">User not found!</span><br/> <span id="user-notfound-notify" class="label label-danger hide">User not found!</span><br/>

Loading…
Cancel
Save