diff --git a/public/src/client/users.js b/public/src/client/users.js index 60f9d6abb1..67d51dc052 100644 --- a/public/src/client/users.js +++ b/public/src/client/users.js @@ -115,7 +115,7 @@ define('forum/users', function() { notify.html(''); - socket.emit('user.search', {query: username}, function(err, data) { + socket.emit('user.search', {query: username, by: $('.search select').val()}, function(err, data) { if (err) { reset(); return app.alertError(err.message); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index aadd177e9a..7b1b7eea0e 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -69,7 +69,7 @@ SocketUser.search = function(socket, data, callback) { if (!socket.uid) { return callback(new Error('[[error:not-logged-in]]')); } - user.search({query: data.query}, callback); + user.search({query: data.query, by: data.by}, callback); }; // Password Reset diff --git a/src/upgrade.js b/src/upgrade.js index 1564b5453c..f5e548e614 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -21,7 +21,7 @@ var db = require('./database'), schemaDate, thisSchemaDate, // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - latestSchema = Date.UTC(2015, 0, 8); + latestSchema = Date.UTC(2015, 0, 9); Upgrade.check = function(callback) { db.get('schemaDate', function(err, value) { @@ -459,7 +459,7 @@ Upgrade.upgrade = function(callback) { db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) { if (err) { - winston.error('[2014/12/20] Error encountered while updating digest settings'); + winston.error('[2015/01/08] Error encountered while Updating category topics sorted sets'); return next(err); } @@ -490,6 +490,41 @@ Upgrade.upgrade = function(callback) { winston.info('[2015/01/08] Updating category topics sorted sets skipped'); next(); } + }, + function(next) { + thisSchemaDate = Date.UTC(2015, 0, 9); + if (schemaDate < thisSchemaDate) { + winston.info('[2015/01/09] Creating fullname:uid hash'); + + db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) { + if (err) { + winston.error('[2014/01/09] Error encountered while Creating fullname:uid hash'); + return next(err); + } + + var now = Date.now(); + + async.eachLimit(uids, 50, function(uid, next) { + db.getObjectFields('user:' + uid, ['fullname'], function(err, userData) { + if (err || !userData || !userData.fullname) { + return next(err); + } + + db.setObjectField('fullname:uid', userData.fullname, uid, next); + }); + }, function(err) { + if (err) { + winston.error('[2015/01/09] Error encountered while Creating fullname:uid hash'); + return next(err); + } + winston.info('[2015/01/09] Creating fullname:uid hash done'); + Upgrade.update(thisSchemaDate, next); + }); + }); + } else { + winston.info('[2015/01/09] Creating fullname:uid hash skipped'); + next(); + } } diff --git a/src/user/profile.js b/src/user/profile.js index 866cc05219..b901bdb066 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -113,6 +113,8 @@ module.exports = function(User) { return updateEmail(uid, data.email, next); } else if (field === 'username') { return updateUsername(uid, data.username, next); + } else if (field === 'fullname') { + return updateFullname(uid, data.fullname, next); } else if (field === 'signature') { data[field] = S(data[field]).stripTags().s; } else if (field === 'website') { @@ -222,6 +224,30 @@ module.exports = function(User) { }); } + function updateFullname(uid, newFullname, callback) { + async.waterfall([ + function(next) { + User.getUserField(uid, 'fullname', next); + }, + function(fullname, next) { + if (newFullname === fullname) { + return callback(); + } + db.deleteObjectField('fullname:uid', fullname, next); + }, + function(next) { + User.setUserField(uid, 'fullname', newFullname, next); + }, + function(next) { + if (newFullname) { + db.setObjectField('fullname:uid', newFullname, uid, next); + } else { + next(); + } + } + ], callback); + } + User.changePassword = function(uid, data, callback) { if (!uid || !data || !data.uid) { return callback(new Error('[[error:invalid-uid]]')); diff --git a/src/user/search.js b/src/user/search.js index 9bc162d097..0df56d94de 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -20,13 +20,10 @@ module.exports = function(User) { } var start = process.hrtime(); - var key = 'username:uid'; - if (by === 'email') { - key = 'email:uid'; - } + var key = by + ':uid'; db.getObject(key, function(err, hash) { - if (err) { + if (err || !hash) { return callback(null, {timing: 0, users:[]}); }