bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-07 23:29:27 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
2017-10-12 09:02:23 +08:00
import RedisPubSub from '/imports/startup/server/redis2x';
2017-02-07 23:29:27 +08:00
import Logger from '/imports/startup/server/logger';
2017-10-12 09:02:23 +08:00
import Users from '/imports/api/2.0/users';
import createDummyUser2x from '../modifiers/createDummyUser';
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;
2017-10-12 09:02:23 +08:00
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'ValidateAuthTokenReqMsg';
2017-02-07 23:29:27 +08:00
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
const User = Users.findOne({
meetingId,
userId: requesterUserId,
});
if (!User) {
2017-10-12 09:02:23 +08:00
createDummyUser2x(meetingId, requesterUserId, requesterToken);
} 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
}
2017-06-03 03:25:02 +08:00
const payload = {
2017-10-12 09:02:23 +08:00
userId: requesterUserId,
authToken: requesterToken,
2017-02-07 23:29:27 +08:00
};
Logger.info(`User '${
requesterUserId
2017-10-12 09:02:23 +08:00
}' is trying to validate auth tokenfor meeting '${meetingId}'`);
2017-02-07 23:29:27 +08:00
2017-10-12 09:02:23 +08:00
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
2017-06-03 03:25:02 +08:00
}