2017-02-07 23:29:27 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
|
2017-02-24 02:52:44 +08:00
|
|
|
import createDummyUser from '../modifiers/createDummyUser';
|
2017-02-24 04:16:10 +08:00
|
|
|
import setConnectionStatus from '../modifiers/setConnectionStatus';
|
|
|
|
|
|
|
|
const ONLINE_CONNECTION_STATUS = 'online';
|
2017-02-07 23:29:27 +08:00
|
|
|
|
|
|
|
export default function validateAuthToken(credentials) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.meeting;
|
|
|
|
const EVENT_NAME = 'validate_auth_token';
|
|
|
|
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
|
|
|
const User = Users.findOne({
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!User) {
|
|
|
|
createDummyUser(meetingId, requesterUserId, requesterToken);
|
2017-02-24 04:16:10 +08:00
|
|
|
} else if (User.validated) {
|
2017-03-03 00:23:53 +08:00
|
|
|
setConnectionStatus(meetingId, requesterUserId, ONLINE_CONNECTION_STATUS);
|
2017-02-07 23:29:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let payload = {
|
|
|
|
auth_token: requesterToken,
|
|
|
|
userid: requesterUserId,
|
|
|
|
meeting_id: meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const header = {
|
|
|
|
reply_to: `${meetingId}/${requesterUserId}`,
|
|
|
|
};
|
|
|
|
|
2017-05-16 23:37:17 +08:00
|
|
|
Logger.info(`User '${requesterUserId}' is trying to validate auth token
|
|
|
|
for meeting '${meetingId}'`);
|
2017-02-07 23:29:27 +08:00
|
|
|
|
|
|
|
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload, header);
|
|
|
|
};
|