bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/createDummyUser.js

38 lines
1000 B
JavaScript
Raw Normal View History

2017-06-19 21:13:35 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
2017-06-19 21:13:35 +08:00
export default function createDummyUser(meetingId, userId, authToken) {
2017-06-19 21:13:35 +08:00
check(meetingId, String);
check(userId, String);
check(authToken, String);
2017-06-29 02:34:22 +08:00
const User = Users.findOne({ meetingId, userId });
if (User) {
2017-06-19 21:13:35 +08:00
throw new Meteor.Error('existing-user', 'Tried to create a dummy user for an existing user');
}
const doc = {
meetingId,
userId,
authToken,
clientType: 'HTML5',
validated: null,
};
const cb = (err, numChanged) => {
if (err) {
2017-10-06 20:50:01 +08:00
Logger.error(`Creating dummy user to collection: ${err}`);
return;
}
if (numChanged) {
Logger.info(`Created dummy user 2x id=${userId} token=${authToken} meeting=${meetingId}`);
2017-06-19 21:13:35 +08:00
}
Logger.info(`Created dummy user id=${userId} token=${authToken} meeting=${meetingId}`);
2017-06-19 21:13:35 +08:00
};
2017-06-29 02:14:29 +08:00
return Users.insert(doc, cb);
2017-06-19 21:13:35 +08:00
}