2017-02-24 02:15:13 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-02-24 04:16:10 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2017-02-24 02:15:13 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
|
2017-02-24 04:16:10 +08:00
|
|
|
import addChat from '/imports/api/chat/server/modifiers/addChat';
|
2017-04-10 22:04:27 +08:00
|
|
|
import clearUserSystemMessages from '/imports/api/chat/server/modifiers/clearUserSystemMessages';
|
2017-02-24 04:16:10 +08:00
|
|
|
|
2017-02-24 02:15:13 +08:00
|
|
|
export default function handleValidateAuthToken({ payload }) {
|
|
|
|
const meetingId = payload.meeting_id;
|
|
|
|
const userId = payload.userid;
|
2017-03-11 02:33:46 +08:00
|
|
|
const validStatus = JSON.parse(payload.valid);
|
2017-02-24 02:15:13 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
2017-03-11 02:33:46 +08:00
|
|
|
check(validStatus, Boolean);
|
2017-02-24 02:15:13 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
2017-03-08 01:18:02 +08:00
|
|
|
const User = Users.findOne(selector);
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
// If we dont find the user on our collection is a flash user and we can skip
|
|
|
|
if (!User) return;
|
2017-03-08 01:18:02 +08:00
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
// User already flagged so we skip
|
|
|
|
if (User.validated === validStatus) return;
|
2017-03-08 01:18:02 +08:00
|
|
|
|
2017-02-24 02:15:13 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
validated: validStatus,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Validating auth token: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2017-02-24 04:16:10 +08:00
|
|
|
if (validStatus) {
|
2017-04-10 22:04:27 +08:00
|
|
|
clearUserSystemMessages(meetingId, userId);
|
2017-02-24 04:16:10 +08:00
|
|
|
addWelcomeChatMessage(meetingId, userId);
|
|
|
|
}
|
|
|
|
|
2017-05-20 00:05:09 +08:00
|
|
|
return Logger.info('Validated auth token as ' + validStatus +
|
|
|
|
+' user=' + userId + ' meeting=' + meetingId
|
|
|
|
);
|
2017-02-24 02:15:13 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.update(selector, modifier, cb);
|
|
|
|
};
|
2017-02-24 04:16:10 +08:00
|
|
|
|
|
|
|
const addWelcomeChatMessage = (meetingId, userId) => {
|
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
|
|
|
|
const Meeting = Meetings.findOne({ meetingId });
|
|
|
|
|
|
|
|
let welcomeMessage = APP_CONFIG.defaultWelcomeMessage
|
2017-04-10 20:55:22 +08:00
|
|
|
.concat(APP_CONFIG.defaultWelcomeMessageFooter)
|
|
|
|
.replace(/%%CONFNAME%%/, Meeting.meetingName);
|
2017-02-24 04:16:10 +08:00
|
|
|
|
|
|
|
const message = {
|
|
|
|
chat_type: CHAT_CONFIG.type_system,
|
|
|
|
message: welcomeMessage,
|
|
|
|
from_color: '0x3399FF',
|
|
|
|
to_userid: userId,
|
|
|
|
from_userid: CHAT_CONFIG.type_system,
|
|
|
|
from_username: '',
|
|
|
|
from_time: (new Date()).getTime(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return addChat(meetingId, message);
|
|
|
|
};
|