From 6760ce00ccf0f7e5131021dc72c617ffdae940cd Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 28 Nov 2014 15:03:33 -0500 Subject: [PATCH 1/2] removed unused msgs --- loader.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/loader.js b/loader.js index c27691036a..20f3c67239 100644 --- a/loader.js +++ b/loader.js @@ -133,8 +133,6 @@ Loader.addClusterEvents = function(callback) { Loader.primaryWorker = parseInt(worker.id, 10); } break; - // case 'user:connect': - // case 'user:disconnect': case 'config:update': Loader.notifyWorkers(message); break; From f9405c04233dcebf46c6c9f618edf2dd9ba0460b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 28 Nov 2014 15:49:16 -0500 Subject: [PATCH 2/2] closes #2440 --- public/src/admin/manage/users.js | 8 ++++---- src/socket.io/admin/categories.js | 2 +- src/socket.io/admin/user.js | 14 +++++++------- src/socket.io/user.js | 2 +- src/user/search.js | 22 ++++++++++++++-------- src/views/admin/manage/users.tpl | 14 ++++++++++++-- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js index 1486f61d3b..79888cc285 100644 --- a/public/src/admin/manage/users.js +++ b/public/src/admin/manage/users.js @@ -215,18 +215,18 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable) } }); - $('#search-user').on('keyup', function() { + $('#search-user-name, #search-user-email').on('keyup', function() { if (timeoutId !== 0) { clearTimeout(timeoutId); timeoutId = 0; } + var $this = $(this); + var type = $this.attr('id') === 'search-user-name' ? 'username' : 'email'; timeoutId = setTimeout(function() { - var username = $('#search-user').val(); - $('.fa-spinner').removeClass('hidden'); - socket.emit('admin.user.search', username, function(err, data) { + socket.emit('admin.user.search', {type: type, query: $this.val()}, function(err, data) { if (err) { return app.alertError(err.message); } diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 5beb66eb7d..9c70e1bdf6 100644 --- a/src/socket.io/admin/categories.js +++ b/src/socket.io/admin/categories.js @@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) { var username = data.username, cid = data.cid; - user.search(username, function(err, data) { + user.search(username, 'username', function(err, data) { if (err) { return callback(err); } diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js index a8ebe9659e..1105ce7c73 100644 --- a/src/socket.io/admin/user.js +++ b/src/socket.io/admin/user.js @@ -165,15 +165,15 @@ User.deleteUsers = function(socket, uids, callback) { }, callback); }; -User.search = function(socket, username, callback) { - user.search(username, function(err, data) { - function isAdmin(userData, next) { - user.isAdministrator(userData.uid, function(err, isAdmin) { - if(err) { +User.search = function(socket, data, callback) { + user.search(data.query, data.type, function(err, data) { + function getEmail(userData, next) { + user.getUserField(userData.uid, 'email', function(err, email) { + if (err) { return next(err); } - userData.administrator = isAdmin; + userData.email = email; next(); }); } @@ -182,7 +182,7 @@ User.search = function(socket, username, callback) { return callback(err); } - async.each(data.users, isAdmin, function(err) { + async.each(data.users, getEmail, function(err) { callback(err, data); }); }); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 96811d57e7..3607e43248 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -66,7 +66,7 @@ SocketUser.search = function(socket, username, callback) { if (!socket.uid) { return callback(new Error('[[error:not-logged-in]]')); } - user.search(username, callback); + user.search(username, 'username', callback); }; // Password Reset diff --git a/src/user/search.js b/src/user/search.js index a4d187cf60..0df73e3cb3 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -1,28 +1,34 @@ 'use strict'; -var db = require('./../database'); +var db = require('../database'); module.exports = function(User) { - User.search = function(query, callback) { + + User.search = function(query, type, callback) { if (!query || query.length === 0) { return callback(null, {timing:0, users:[]}); } var start = process.hrtime(); - db.getObject('username:uid', function(err, usernamesHash) { + var set = 'username:uid'; + if (type === 'email') { + set = 'email:uid'; + } + + db.getObject(set, function(err, hash) { if (err) { return callback(null, {timing: 0, users:[]}); } query = query.toLowerCase(); - var usernames = Object.keys(usernamesHash); + var values = Object.keys(hash); var uids = []; - for(var i=0; i b; }) .map(function(username) { - return usernamesHash[username]; + return hash[username]; }); User.getUsers(uids, function(err, userdata) { diff --git a/src/views/admin/manage/users.tpl b/src/views/admin/manage/users.tpl index 51121c94c0..7737d919ec 100644 --- a/src/views/admin/manage/users.tpl +++ b/src/views/admin/manage/users.tpl @@ -32,9 +32,16 @@
@@ -54,7 +61,10 @@ - {users.username} ({users.uid}) + {users.username} ({users.uid})
+ + {users.email} +