2017-02-07 23:29:27 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-02-07 23:29:27 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-10-13 03:07:02 +08:00
|
|
|
import createDummyUser from '../modifiers/createDummyUser';
|
2018-02-20 22:21:51 +08:00
|
|
|
import setConnectionId from '../modifiers/setConnectionId';
|
2017-02-07 23:29:27 +08:00
|
|
|
|
|
|
|
export default function validateAuthToken(credentials) {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.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);
|
|
|
|
|
2018-02-20 22:21:51 +08:00
|
|
|
const sessionId = `${meetingId}-${requesterUserId}`;
|
|
|
|
this.setUserId(sessionId);
|
|
|
|
|
2017-02-07 23:29:27 +08:00
|
|
|
const User = Users.findOne({
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!User) {
|
2017-10-13 03:07:02 +08:00
|
|
|
createDummyUser(meetingId, requesterUserId, requesterToken);
|
2017-02-07 23:29:27 +08:00
|
|
|
}
|
|
|
|
|
2018-03-29 20:10:30 +08:00
|
|
|
setConnectionId(meetingId, requesterUserId, this.connection.id, requesterToken);
|
2018-02-20 22:21:51 +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
|
|
|
};
|
|
|
|
|
2018-02-20 22:21:51 +08:00
|
|
|
Logger.info(`User '${requesterUserId}' is trying to validate auth token for 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
|
|
|
}
|