diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js index c762bc68f4..75ab7e224c 100644 --- a/public/src/admin/manage/users.js +++ b/public/src/admin/manage/users.js @@ -267,14 +267,21 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable) handleUserCreate(); - function onUsersLoaded(users) { - templates.parse('admin/manage/users', 'users', {users: users, requireEmailConfirmation: config.requireEmailConfirmation}, function(html) { - $('#users-container').append($(html)); - selectable.enable('#users-container', '.user-selectable'); - }); - } + $('#load-more-users-btn').on('click', loadMoreUsers); + + $(window).off('scroll').on('scroll', function() { + var bottom = ($(document).height() - $(window).height()) * 0.9; + + if ($(window).scrollTop() > bottom && !loadingMoreUsers) { + loadMoreUsers(); + } + }); + function loadMoreUsers() { + if (active === 'search') { + return; + } var set = 'users:joindate'; if (active === 'sort-posts') { set = 'users:postcount'; @@ -284,7 +291,6 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable) set = 'users:banned'; } - loadingMoreUsers = true; socket.emit('user.loadMore', { set: set, @@ -297,15 +303,12 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable) }); } - $('#load-more-users-btn').on('click', loadMoreUsers); - - $(window).off('scroll').on('scroll', function() { - var bottom = ($(document).height() - $(window).height()) * 0.9; - - if ($(window).scrollTop() > bottom && !loadingMoreUsers) { - loadMoreUsers(); - } - }); + function onUsersLoaded(users) { + templates.parse('admin/manage/users', 'users', {users: users, requireEmailConfirmation: config.requireEmailConfirmation}, function(html) { + $('#users-container').append($(html)); + selectable.enable('#users-container', '.user-selectable'); + }); + } }; diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index f750c6648b..17944b8370 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -9,7 +9,7 @@ var usersController = {}; usersController.search = function(req, res, next) { res.render('admin/manage/users', { search_display: '', - loadmore_display: 'none', + loadmore_display: 'hide', users: [] }); }; @@ -52,6 +52,9 @@ function getUsers(set, req, res, next) { usersController.getCSV = function(req, res, next) { user.getUsersCSV(function(err, data) { + if (err) { + return next(err); + } res.attachment('users.csv'); res.setHeader('Content-Type', 'text/csv'); res.end(data); diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 00992fc4b4..2ba036d7e0 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, 'username', function(err, data) { + user.search({query: 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 2184ee83c2..bcb78b223f 100644 --- a/src/socket.io/admin/user.js +++ b/src/socket.io/admin/user.js @@ -175,7 +175,7 @@ User.deleteUsers = function(socket, uids, callback) { }; User.search = function(socket, data, callback) { - user.search(data.query, data.type, function(err, searchData) { + user.search({query: data.query, by: data.type, startsWith: false}, function(err, searchData) { if (err) { return callback(err); } diff --git a/src/socket.io/user.js b/src/socket.io/user.js index a7ca2d6605..e20ff65bbb 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, 'username', callback); + user.search({query: username}, callback); }; // Password Reset diff --git a/src/user/search.js b/src/user/search.js index 1400c63a67..9bc162d097 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -6,18 +6,22 @@ var async = require('async'), module.exports = function(User) { - User.search = function(query, type, callback) { + User.search = function(data, callback) { + var query = data.query; + var by = data.by || 'username'; + var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true; + if (!query || query.length === 0) { return callback(null, {timing:0, users:[]}); } - if (type === 'ip') { + if (by === 'ip') { return searchByIP(query, callback); } var start = process.hrtime(); var key = 'username:uid'; - if (type === 'email') { + if (by === 'email') { key = 'email:uid'; } @@ -32,7 +36,11 @@ module.exports = function(User) { var uids = []; for(var i=0; i