From 8e06ff49f3daa886f4e6413452e1f3e52575c81c Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 2 Oct 2015 17:26:12 -0400 Subject: [PATCH] check user exists before chat --- src/messaging.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/messaging.js b/src/messaging.js index 8ffb3a579e..f438f3a23c 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -76,7 +76,7 @@ var db = require('./database'), async.apply(Messaging.updateChatTime, touid, fromuid), async.apply(Messaging.markRead, fromuid, touid), async.apply(Messaging.markUnread, touid, fromuid), - ], function(err, results) { + ], function(err) { if (err) { return callback(err); } @@ -365,29 +365,29 @@ var db = require('./database'), return callback(new Error('[[error:chat-disabled]]')); } else if (toUid === fromUid) { return callback(new Error('[[error:cant-chat-with-yourself]]')); - } else if (fromUid === 0) { + } else if (!fromUid) { return callback(new Error('[[error:not-logged-in]]')); } async.waterfall([ - function(next) { - user.getUserFields(fromUid, ['banned', 'email:confirmed'], function(err, userData) { - if (err) { - return callback(err); - } - - if (parseInt(userData.banned, 10) === 1) { - return callback(new Error('[[error:user-banned]]')); - } + function (next) { + user.exists(toUid, next); + }, + function (exists, next) { + if (!exists) { + return next(new Error('[[error:no-user]]')); + } + user.getUserFields(fromUid, ['banned', 'email:confirmed'], next); + }, + function (userData, next) { + if (parseInt(userData.banned, 10) === 1) { + return next(new Error('[[error:user-banned]]')); + } - if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { - return callback(new Error('[[error:email-not-confirmed-chat]]')); - } + if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { + return next(new Error('[[error:email-not-confirmed-chat]]')); + } - next(); - }); - }, - function(next) { user.getSettings(toUid, next); }, function(settings, next) {