Skip to content

Node.js based forum software built for the modern web

check user exists before chat

barisusakli8e06ff49f3da
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) {