Baris Soner Usakli 11 years ago
commit 5a069f1076

@ -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);
}

@ -67,15 +67,9 @@ var DebugRoute = function(app) {
topics.reIndexAll(function (err) {
if (err) {
return res.json(err);
} else {
res.send('Topics and users reindexed');
}
user.reIndexAll(function (err) {
if (err) {
return res.json(err);
} else {
res.send('Topics and users reindexed');
}
});
});
});

@ -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 = {};

@ -17,7 +17,7 @@ var db = require('./database'),
Upgrade.check = function(callback) {
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
var latestSchema = new Date(2014, 0, 13, 12, 0).getTime();
var latestSchema = new Date(2014, 0, 19, 22, 19).getTime();
db.get('schemaDate', function(err, value) {
if (parseInt(value, 10) >= latestSchema) {
@ -281,6 +281,24 @@ Upgrade.upgrade = function(callback) {
winston.info('[2014/1/13] Set up "Registered Users" user group - skipped');
next();
}
},
function(next) {
thisSchemaDate = new Date(2014, 0, 19, 22, 19).getTime();
if (schemaDate < thisSchemaDate) {
updatesMade = true;
db.getObjectValues('username:uid', function(err, uids) {
async.each(uids, function(uid, next) {
db.searchRemove('user', uid, next);
}, function(err) {
winston.info('[2014/1/19] Remove user search from Reds');
next();
});
});
} else {
winston.info('[2014/1/19] Remove user search from Reds -- skipped');
next();
}
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!

@ -115,8 +115,6 @@ var bcrypt = require('bcrypt'),
db.sortedSetAdd('users:postcount', 0, uid);
db.sortedSetAdd('users:reputation', 0, uid);
db.searchIndex('user', username, uid);
// Join the "registered-users" meta group
groups.joinByGroupName('registered-users', uid);
@ -309,7 +307,6 @@ var bcrypt = require('bcrypt'),
db.deleteObjectField('username:uid', userData.username);
db.setObjectField('username:uid', data.username, uid);
events.logUsernameChange(uid, userData.username, data.username);
User.reIndexUser(uid, data.username);
}
if(userslug !== userData.userslug) {
@ -438,26 +435,6 @@ var bcrypt = require('bcrypt'),
});
};
User.reIndexAll = function(callback) {
User.getUsers('users:joindate', 0, -1, function(err, usersData) {
if (err) {
return callback(err, null);
}
for (var i = 0; i < usersData.length; ++i) {
User.reIndexUser(usersData[i].uid, usersData[i].username);
}
callback(null, 1);
});
};
User.reIndexUser = function(uid, username) {
db.searchRemove('user', uid, function() {
db.searchIndex('user', username, uid);
});
};
// thanks to @akhoury
User.getUsersCSV = function(callback) {
var csvContent = "";
@ -482,23 +459,36 @@ var bcrypt = require('bcrypt'),
});
}
User.search = function(username, callback) {
if (!username) {
return 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);
var usernames = Object.keys(usernamesHash),
filterRegex = new RegExp('^' + query + '.*?$'),
results = [];
results = usernames.filter(function(username) { // Remove non-matches
return filterRegex.test(username);
}).sort(function(a, b) { // Sort alphabetically
return a > b;
}).slice(0, 5) // Limit 5
.map(function(username) { // Translate to uids
return usernamesHash[username];
});
if (results && results.length) {
User.getDataForUsers(results, function(userdata) {
callback(null, userdata);
});
} else {
callback([]);
callback(null, []);
}
});
};

Loading…
Cancel
Save