Skip to content

Node.js based forum software built for the modern web

closes #2491

barisusakli612aa4e55b7e
diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js
index 79888cc285..b59292861f 100644
--- a/public/src/admin/manage/users.js
+++ b/public/src/admin/manage/users.js
@@ -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) {
clearTimeout(timeoutId);
timeoutId = 0;
}
+
var $this = $(this);
- var type = $this.attr('id') === 'search-user-name' ? 'username' : 'email';
+ var type = $this.attr('data-search-type');
timeoutId = setTimeout(function() {
$('.fa-spinner').removeClass('hidden');
diff --git a/src/user/admin.js b/src/user/admin.js
index ab94a35193..c919193b10 100644
--- a/src/user/admin.js
+++ b/src/user/admin.js
@@ -8,7 +8,11 @@ var async = require('async'),
module.exports = function(User) {
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) {
diff --git a/src/user/search.js b/src/user/search.js
index 0df73e3cb3..dc5bb7d585 100644
--- a/src/user/search.js
+++ b/src/user/search.js
@@ -1,7 +1,8 @@
'use strict';
-var db = require('../database');
+var async = require('async'),
+ db = require('../database');
module.exports = function(User) {
@@ -9,14 +10,18 @@ module.exports = function(User) {
if (!query || query.length === 0) {
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') {
- set = 'email:uid';
+ key = 'email:uid';
}
- db.getObject(set, function(err, hash) {
+ db.getObject(key, function(err, hash) {
if (err) {
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);
+ }
};
diff --git a/src/views/admin/manage/users.tpl b/src/views/admin/manage/users.tpl
index 7737d919ec..e32106c900 100644
--- a/src/views/admin/manage/users.tpl
+++ b/src/views/admin/manage/users.tpl
@@ -33,10 +33,13 @@
<div class="search {search_display} well">
<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>
- <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>
<span id="user-notfound-notify" class="label label-danger hide">User not found!</span><br/>