|
|
|
@ -482,24 +482,49 @@ var bcrypt = require('bcrypt'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.search = function(username, callback) {
|
|
|
|
|
if (!username) {
|
|
|
|
|
return callback([]);
|
|
|
|
|
// 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, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.search('user', username, 50, function(err, uids) {
|
|
|
|
|
// TODO: Have this use db.getObjectKeys (doesn't exist yet)
|
|
|
|
|
db.getObject('username:uid', function(err, usernamesHash) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
return;
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uids && uids.length) {
|
|
|
|
|
User.getDataForUsers(uids, function(userdata) {
|
|
|
|
|
callback(userdata);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
callback([]);
|
|
|
|
|
}
|
|
|
|
|
var usernames = Object.keys(usernamesHash),
|
|
|
|
|
filterRegex = new RegExp('^' + query + '.*?$'),
|
|
|
|
|
results = [];
|
|
|
|
|
|
|
|
|
|
results = usernames.filter(function(username) { // Remove non-matches
|
|
|
|
|
return filterRegex.text(username);
|
|
|
|
|
}).sort(function(a, b) { // Sort alphabetically
|
|
|
|
|
return a > b;
|
|
|
|
|
}).slice(0, 5); // Limit 5
|
|
|
|
|
|
|
|
|
|
callback(null, results);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|