added alphanumeric user search (instead of using reds), and exposed a proper socket call for user searching for non-admins

v1.18.x
Julian Lam 11 years ago
parent 483ad87c1d
commit e542da1f52

@ -47,7 +47,7 @@ define(function() {
jQuery('#user-notfound-notify').html('<i class="fa fa-spinner fa-spin"></i>');
setTimeout(function() {
socket.emit('admin.user.search', username, function(err, data) {
socket.emit('user.search', username, function(err, data) {
if(err) {
return app.alert(err.message);
}

@ -79,7 +79,7 @@ SocketAdmin.user.unbanUser = function(socket, theirid) {
};
SocketAdmin.user.search = function(socket, username, callback) {
user.search(username, function(data) {
user.search(username, function(err, data) {
function isAdmin(userData, next) {
user.isAdministrator(userData.uid, function(err, isAdmin) {
if(err) {
@ -125,7 +125,7 @@ SocketAdmin.categories.search = function(socket, data, callback) {
var username = data.username,
cid = data.cid;
user.search(username, function(data) {
user.search(username, function(err, data) {
async.map(data, function(userObj, next) {
CategoryTools.privileges(cid, userObj.uid, function(err, privileges) {
if(err) {

@ -19,6 +19,10 @@ SocketUser.emailExists = function(socket, data, callback) {
}
};
SocketUser.search = function(socket, username, callback) {
user.search(username, callback);
};
// Password Reset
SocketUser.reset = {};

@ -482,27 +482,6 @@ var bcrypt = require('bcrypt'),
});
}
// User.search = function(username, callback) {
// if (!username) {
// return callback([]);
// }
// db.search('user', username, 50, function(err, uids) {
// if (err) {
// console.log(err);
// return;
// }
// if (uids && uids.length) {
// User.getDataForUsers(uids, function(userdata) {
// callback(userdata);
// });
// } else {
// callback([]);
// }
// });
// };
User.search = function(query, callback) {
if (!query || query.length === 0) {
return callback(null, []);
@ -519,12 +498,21 @@ var bcrypt = require('bcrypt'),
results = [];
results = usernames.filter(function(username) { // Remove non-matches
return filterRegex.text(username);
return filterRegex.test(username);
}).sort(function(a, b) { // Sort alphabetically
return a > b;
}).slice(0, 5); // Limit 5
}).slice(0, 5) // Limit 5
.map(function(username) { // Translate to uids
return usernamesHash[username];
});
callback(null, results);
if (results && results.length) {
User.getDataForUsers(results, function(userdata) {
callback(null, userdata);
});
} else {
callback(null, []);
}
});
};

Loading…
Cancel
Save