diff --git a/src/socket.io/user.js b/src/socket.io/user.js index f62e95ccfd..c3094fbcff 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -1,3 +1,5 @@ +'use strict'; + var async = require('async'), user = require('../user'), topics = require('../topics'), @@ -93,8 +95,9 @@ SocketUser.updateProfile = function(socket, data, callback) { if(err) { return callback(err); } + if(!isAdmin) { - return callback(new Error('not allowed!')) + return callback(new Error('not allowed!')); } user.updateProfile(data.uid, data, callback); diff --git a/src/user.js b/src/user.js index 78184bdbdd..fcabfbb0de 100644 --- a/src/user.js +++ b/src/user.js @@ -27,6 +27,7 @@ var bcrypt = require('bcryptjs'), require('./user/profile')(User); require('./user/admin')(User); require('./user/settings')(User); + require('./user/search')(User); User.create = function(userData, callback) { userData = userData || {}; @@ -338,44 +339,6 @@ var bcrypt = require('bcryptjs'), }); }; - User.search = function(query, callback) { - if (!query || query.length === 0) { - return callback(null, {timing:0, users:[]}); - } - var start = process.hrtime(); - - db.getObject('username:uid', function(err, usernamesHash) { - if (err) { - return callback(null, {timing: 0, users:[]}); - } - - query = query.toLowerCase(); - - var usernames = Object.keys(usernamesHash), - uids = []; - - uids = usernames.filter(function(username) { - return username.toLowerCase().indexOf(query) === 0; - }) - .slice(0, 10) - .sort(function(a, b) { - return a > b; - }) - .map(function(username) { - return usernamesHash[username]; - }); - - User.getUsersData(uids, function(err, userdata) { - if (err) { - return callback(err); - } - var diff = process.hrtime(start); - var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1); - callback(null, {timing: timing, users: userdata}); - }); - }); - }; - User.onNewPostMade = function(uid, tid, pid, timestamp) { User.addPostIdToUser(uid, pid, timestamp); diff --git a/src/user/search.js b/src/user/search.js new file mode 100644 index 0000000000..587f175352 --- /dev/null +++ b/src/user/search.js @@ -0,0 +1,45 @@ + +'use strict'; + +var db = require('./../database'); + +module.exports = function(User) { + User.search = function(query, callback) { + if (!query || query.length === 0) { + return callback(null, {timing:0, users:[]}); + } + var start = process.hrtime(); + + db.getObject('username:uid', function(err, usernamesHash) { + if (err) { + return callback(null, {timing: 0, users:[]}); + } + + query = query.toLowerCase(); + + var usernames = Object.keys(usernamesHash), + uids = []; + + uids = usernames.filter(function(username) { + return username.toLowerCase().indexOf(query) === 0; + }) + .slice(0, 10) + .sort(function(a, b) { + return a > b; + }) + .map(function(username) { + return usernamesHash[username]; + }); + + User.getUsersData(uids, function(err, userdata) { + if (err) { + return callback(err); + } + var diff = process.hrtime(start); + var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1); + callback(null, {timing: timing, users: userdata}); + }); + }); + }; +}; +