2017-06-19 21:13:35 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Meetings from '/imports/api/2.0/meetings';
|
2017-06-28 06:14:53 +08:00
|
|
|
import Users from '/imports/api/2.0/users';
|
2017-06-19 21:13:35 +08:00
|
|
|
|
2017-07-12 20:42:16 +08:00
|
|
|
import addChat from '/imports/api/2.0/chat/server/modifiers/addChat';
|
|
|
|
import clearUserSystemMessages from '/imports/api/2.0/chat/server/modifiers/clearUserSystemMessages';
|
2017-06-19 21:13:35 +08:00
|
|
|
|
2017-06-29 04:04:41 +08:00
|
|
|
const addWelcomeChatMessage = (meetingId, userId) => {
|
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
|
2017-07-18 21:25:11 +08:00
|
|
|
const Meeting = Meetings.findOne({ meetingId });
|
2017-06-29 04:04:41 +08:00
|
|
|
|
|
|
|
const message = {
|
2017-07-18 21:25:11 +08:00
|
|
|
message: Meeting.welcomeProp.welcomeMsg,
|
2017-07-12 20:42:16 +08:00
|
|
|
fromColor: '0x3399FF',
|
2017-07-14 00:55:05 +08:00
|
|
|
toUserId: userId,
|
2017-07-20 01:57:07 +08:00
|
|
|
toUsername: CHAT_CONFIG.type_system,
|
2017-07-14 00:55:05 +08:00
|
|
|
fromUserId: CHAT_CONFIG.type_system,
|
|
|
|
fromUsername: '',
|
2017-07-12 20:42:16 +08:00
|
|
|
fromTime: (new Date()).getTime(),
|
2017-06-29 04:04:41 +08:00
|
|
|
};
|
|
|
|
|
2017-07-14 22:18:07 +08:00
|
|
|
addChat(meetingId, message);
|
2017-06-29 04:04:41 +08:00
|
|
|
};
|
|
|
|
|
2017-06-29 21:09:11 +08:00
|
|
|
export default function handleValidateAuthToken({ body }, meetingId) {
|
2017-07-14 22:18:07 +08:00
|
|
|
const { userId, valid, waitForApproval } = body;
|
2017-06-19 21:13:35 +08:00
|
|
|
|
|
|
|
check(userId, String);
|
|
|
|
check(valid, Boolean);
|
2017-07-14 22:18:07 +08:00
|
|
|
check(waitForApproval, Boolean);
|
2017-06-19 21:13:35 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const User = Users.findOne(selector);
|
|
|
|
|
|
|
|
// If we dont find the user on our collection is a flash user and we can skip
|
|
|
|
if (!User) return;
|
|
|
|
|
|
|
|
// User already flagged so we skip
|
|
|
|
if (User.validated === valid) return;
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
validated: valid,
|
2017-07-14 22:18:07 +08:00
|
|
|
approved: !waitForApproval,
|
2017-06-19 21:13:35 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
2017-07-15 03:25:04 +08:00
|
|
|
return Logger.error(`Validating auth token: ${err}`);
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2017-07-14 22:23:12 +08:00
|
|
|
if (valid) {
|
2017-06-19 21:13:35 +08:00
|
|
|
clearUserSystemMessages(meetingId, userId);
|
|
|
|
addWelcomeChatMessage(meetingId, userId);
|
|
|
|
}
|
|
|
|
|
2017-07-15 03:25:04 +08:00
|
|
|
return Logger.info(`Validated auth token as ${valid
|
2017-06-19 21:13:35 +08:00
|
|
|
}${+' user='}${userId} meeting=${meetingId}`,
|
|
|
|
);
|
|
|
|
}
|
2017-07-12 21:18:26 +08:00
|
|
|
|
2017-07-15 03:25:04 +08:00
|
|
|
return Logger.info('No auth to validate');
|
2017-06-19 21:13:35 +08:00
|
|
|
};
|
|
|
|
|
2017-07-14 22:18:07 +08:00
|
|
|
Users.update(selector, modifier, cb);
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|