Node.js based forum software built for the modern web
added some missing callbacks
barisusaklif7aa44d1bf3b
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.jsindex 853d3f1536..6dd22134ba 100644--- a/src/socket.io/admin.js+++ b/src/socket.io/admin.js@@ -8,7 +8,7 @@ var async = require('async'),plugins = require('../plugins'),widgets = require('../widgets'),user = require('../user'),- posts = require('../posts'),+logger = require('../logger'),events = require('../events'),emailer = require('../emailer'),@@ -60,6 +60,7 @@ SocketAdmin.reload = function(socket, data, callback) {process.send({action: 'reload'});+ callback();} else {meta.reload(callback);}@@ -72,10 +73,12 @@ SocketAdmin.restart = function(socket, data, callback) {ip: socket.ip});meta.restart();+ callback();};SocketAdmin.fireEvent = function(socket, data, callback) {index.server.emit(data.name, data.payload || {});+ callback();};SocketAdmin.themes.getInstalled = function(socket, data, callback) {@@ -83,7 +86,7 @@ SocketAdmin.themes.getInstalled = function(socket, data, callback) {};SocketAdmin.themes.set = function(socket, data, callback) {- if(!data) {+ if (!data) {return callback(new Error('[[error:invalid-data]]'));}@@ -134,16 +137,16 @@ SocketAdmin.widgets.set = function(socket, data, callback) {};SocketAdmin.config.set = function(socket, data, callback) {- if(!data) {+ if (!data) {return callback(new Error('[[error:invalid-data]]'));}meta.configs.set(data.key, data.value, function(err) {- if(err) {+ if (err) {return callback(err);}- callback(null);+ callback();plugins.fireHook('action:config.set', {key: data.key,@@ -155,7 +158,7 @@ SocketAdmin.config.set = function(socket, data, callback) {};SocketAdmin.config.setMultiple = function(socket, data, callback) {- if(!data) {+ if (!data) {return callback(new Error('[[error:invalid-data]]'));}@@ -179,8 +182,9 @@ SocketAdmin.config.setMultiple = function(socket, data, callback) {});};-SocketAdmin.config.remove = function(socket, key) {+SocketAdmin.config.remove = function(socket, key, callback) {meta.configs.remove(key);+ callback();};SocketAdmin.settings.get = function(socket, data, callback) {diff --git a/src/socket.io/notifications.js b/src/socket.io/notifications.jsindex 7fc25141bb..e2d7cf3084 100644--- a/src/socket.io/notifications.js+++ b/src/socket.io/notifications.js@@ -19,7 +19,7 @@ SocketNotifs.loadMore = function(socket, data, callback) {return callback(new Error('[[error:invalid-data]]'));}if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));}var start = parseInt(data.after, 10);var stop = start + 20;@@ -37,7 +37,7 @@ SocketNotifs.getCount = function(socket, data, callback) {SocketNotifs.deleteAll = function(socket, data, callback) {if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));}user.notifications.deleteAll(socket.uid, callback);@@ -57,7 +57,7 @@ SocketNotifs.markAllRead = function(socket, data, callback) {SocketNotifs.generatePath = function(socket, nid, callback) {if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));;}async.waterfall([function (next) {diff --git a/src/socket.io/plugins.js b/src/socket.io/plugins.jsindex aad0bb2841..32f1e7f00f 100644--- a/src/socket.io/plugins.js+++ b/src/socket.io/plugins.js@@ -9,7 +9,7 @@ var SocketPlugins = {};var SocketPlugins = require.main.require('./src/socket.io/plugins');SocketPlugins.myPlugin = {};- SocketPlugins.myPlugin.myMethod = function() { ... };+ SocketPlugins.myPlugin.myMethod = function(socket, data, callback) { ... };Be a good lad and namespace your methods.*/diff --git a/src/socket.io/topics/tools.js b/src/socket.io/topics/tools.jsindex 35e1118986..f3d9ad4688 100644--- a/src/socket.io/topics/tools.js+++ b/src/socket.io/topics/tools.js@@ -11,7 +11,7 @@ module.exports = function(SocketTopics) {SocketTopics.loadTopicTools = function(socket, data, callback) {if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));}if (!data) {return callback(new Error('[[error:invalid-data]]'));@@ -74,7 +74,7 @@ module.exports = function(SocketTopics) {SocketTopics.doTopicAction = function(action, event, socket, data, callback) {callback = callback || function() {};if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));}if (!data || !Array.isArray(data.tids) || !data.cid) {diff --git a/src/socket.io/user.js b/src/socket.io/user.jsindex 2f33ef9f87..06acacd520 100644--- a/src/socket.io/user.js+++ b/src/socket.io/user.js@@ -23,14 +23,15 @@ require('./user/picture')(SocketUser);require('./user/ban')(SocketUser);SocketUser.exists = function(socket, data, callback) {- if (data && data.username) {- meta.userOrGroupExists(data.username, callback);+ if (!data || !data.username) {+ return callback(new Error('[[error:invalid-data]]'));}+ meta.userOrGroupExists(data.username, callback);};SocketUser.deleteAccount = function(socket, data, callback) {if (!socket.uid) {- return;+ return callback(new Error('[[error:no-privileges]]'));}async.waterfall([@@ -58,25 +59,27 @@ SocketUser.deleteAccount = function(socket, data, callback) {};SocketUser.emailExists = function(socket, data, callback) {- if (data && data.email) {- user.email.exists(data.email, callback);+ if (!data || !data.email) {+ return callback(new Error('[[error:invalid-data]]'));}+ user.email.exists(data.email, callback);};SocketUser.emailConfirm = function(socket, data, callback) {- if (socket.uid && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {- user.getUserField(socket.uid, 'email', function(err, email) {- if (err) {- return callback(err);- }-- if (!email) {- return;- }+ if (!socket.uid) {+ return callback(new Error('[[error:no-privileges]]'));+ }- user.email.sendValidationEmail(socket.uid, email, callback);- });+ if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {+ callback();}+ user.getUserField(socket.uid, 'email', function(err, email) {+ if (err || !email) {+ return callback(err);+ }++ user.email.sendValidationEmail(socket.uid, email, callback);+ });};@@ -84,9 +87,11 @@ SocketUser.emailConfirm = function(socket, data, callback) {SocketUser.reset = {};SocketUser.reset.send = function(socket, email, callback) {- if (email) {- user.reset.send(email, callback);+ if (!email) {+ return callback(new Error('[[error:invalid-data]]'));}++ user.reset.send(email, callback);};SocketUser.reset.commit = function(socket, data, callback) {@@ -102,9 +107,9 @@ SocketUser.reset.commit = function(socket, data, callback) {return callback(err);}- var uid = results.uid,- now = new Date(),- parsedDate = now.getFullYear() + '/' + (now.getMonth()+1) + '/' + now.getDate();+ var uid = results.uid;+ var now = new Date();+ var parsedDate = now.getFullYear() + '/' + (now.getMonth()+1) + '/' + now.getDate();user.getUserField(uid, 'username', function(err, username) {emailer.send('reset_notify', uid, {@@ -134,7 +139,7 @@ SocketUser.isFollowing = function(socket, data, callback) {SocketUser.follow = function(socket, data, callback) {if (!socket.uid || !data) {- return;+ return callback(new Error('[[error:invalid-data]]'));}var userData;async.waterfall([@@ -165,9 +170,10 @@ SocketUser.follow = function(socket, data, callback) {};SocketUser.unfollow = function(socket, data, callback) {- if (socket.uid && data) {- toggleFollow('unfollow', socket.uid, data.uid, callback);+ if (!socket.uid || !data) {+ return callback(new Error('[[error:invalid-data]]'));}+ toggleFollow('unfollow', socket.uid, data.uid, callback);};function toggleFollow(method, uid, theiruid, callback) {@@ -206,15 +212,17 @@ SocketUser.saveSettings = function(socket, data, callback) {};SocketUser.setTopicSort = function(socket, sort, callback) {- if (socket.uid) {- user.setSetting(socket.uid, 'topicPostSort', sort, callback);+ if (!socket.uid) {+ return callback();}+ user.setSetting(socket.uid, 'topicPostSort', sort, callback);};SocketUser.setCategorySort = function(socket, sort, callback) {- if (socket.uid) {- user.setSetting(socket.uid, 'categoryTopicSort', sort, callback);+ if (!socket.uid) {+ return callback();}+ user.setSetting(socket.uid, 'categoryTopicSort', sort, callback);};SocketUser.getUnreadCount = function(socket, data, callback) {diff --git a/src/socket.io/user/picture.js b/src/socket.io/user/picture.jsindex 55caa37857..cf886b1d48 100644--- a/src/socket.io/user/picture.js+++ b/src/socket.io/user/picture.js@@ -51,7 +51,7 @@ module.exports = function(SocketUser) {SocketUser.uploadProfileImageFromUrl = function(socket, data, callback) {if (!socket.uid || !data.url || !data.uid) {- return;+ return callback(new Error('[[error:invalid-data]]'));}user.isAdminOrSelf(socket.uid, data.uid, function(err) {@@ -66,7 +66,7 @@ module.exports = function(SocketUser) {SocketUser.removeUploadedPicture = function(socket, data, callback) {if (!socket.uid || !data.uid) {- return;+ return callback(new Error('[[error:invalid-data]]'));}async.waterfall([