From ecd3b3de178d41174f1a4b31dc1d3ee86d752a0e Mon Sep 17 00:00:00 2001
From: Anton Georgiev <anto.georgiev@gmail.com>
Date: Thu, 12 May 2016 19:22:51 +0000
Subject: [PATCH] log in user properly

---
 bbb-api-demo/src/main/webapp/demoHTML5.jsp    |   2 +-
 .../users/server/methods/validateAuthToken.js |   2 +-
 .../api/users/server/modifiers/userJoined.js  |   1 +
 .../imports/api/users/server/publications.js  | 145 ++++++++----------
 .../imports/ui/components/app/AppService.js   |  10 +-
 5 files changed, 79 insertions(+), 81 deletions(-)

diff --git a/bbb-api-demo/src/main/webapp/demoHTML5.jsp b/bbb-api-demo/src/main/webapp/demoHTML5.jsp
index 4b9a550b77..1fe4e1626a 100644
--- a/bbb-api-demo/src/main/webapp/demoHTML5.jsp
+++ b/bbb-api-demo/src/main/webapp/demoHTML5.jsp
@@ -98,7 +98,7 @@ if (request.getParameterMap().isEmpty()) {
 	String ip = BigBlueButtonURL.split("\\/bigbluebutton")[0];
 
 	// redirect towards the html5 client which is waiting for the following parameters
-	String html5url = ip + "/html5client/" + meetingId + "/" + userId + "/" + authToken;
+	String html5url = ip + "/html5client/join/" + meetingId + "/" + userId + "/" + authToken;
 
 	if (joinURL.startsWith("http://") || joinURL.startsWith("https://")) {
 %>
diff --git a/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js b/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js
index 20ea332fd0..4ce9ea4a71 100644
--- a/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js
+++ b/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js
@@ -1,6 +1,6 @@
 import { logger } from '/imports/startup/server/logger';
 import { redisConfig } from '/config';
-import { createDummyUser } from '/imports/api/users/server/modifiers/clearUsersCollection';
+import { createDummyUser } from '/imports/api/users/server/modifiers/createDummyUser';
 import { publish } from '/imports/startup/server/helpers';
 
 Meteor.methods({
diff --git a/bigbluebutton-html5/imports/api/users/server/modifiers/userJoined.js b/bigbluebutton-html5/imports/api/users/server/modifiers/userJoined.js
index 6ffaa1417d..b9c018f6a4 100644
--- a/bigbluebutton-html5/imports/api/users/server/modifiers/userJoined.js
+++ b/bigbluebutton-html5/imports/api/users/server/modifiers/userJoined.js
@@ -1,5 +1,6 @@
 import Chat from '/imports/api/chat/collection';
 import Users from '/imports/api/users/collection';
+import Meetings from '/imports/api/meetings/collection';
 import { logger } from '/imports/startup/server/logger';
 
 export function userJoined(meetingId, user, callback) {
diff --git a/bigbluebutton-html5/imports/api/users/server/publications.js b/bigbluebutton-html5/imports/api/users/server/publications.js
index cdd4a04661..39d5010b0d 100644
--- a/bigbluebutton-html5/imports/api/users/server/publications.js
+++ b/bigbluebutton-html5/imports/api/users/server/publications.js
@@ -1,91 +1,80 @@
 import Users from '/imports/api/users/collection';
 import { isAllowedTo } from '/imports/startup/server/userPermissions';
 import { logger } from '/imports/startup/server/logger';
+import { requestUserLeaving } from '/imports/api/users/server/modifiers/requestUserLeaving';
 
 // Publish only the online users that are in the particular meetingId
 // On the client side we pass the meetingId parameter
-/*Meteor.publish('users', function (meetingId, userid, authToken) {
- let user, userObject, username;
- logger.info(`attempt publishing users for ${meetingId}, ${userid}, ${authToken}`);
- userObject = Users.findOne({
- userId: userid,
- meetingId: meetingId,
- });
- if (userObject != null) {
- logger.info('found it from the first time ' + userid);
- if (isAllowedTo('subscribeUsers', meetingId, userid, authToken)) {
- logger.info(`${userid} was allowed to subscribe to 'users'`);
- user = userObject.user;
- if (user != null) {
- username = user.name;
+Meteor.publish('users', function (meetingId, userid, authToken) {
+  let username;
+  logger.info(`attempt publishing users for ${meetingId}, ${userid}, ${authToken}`);
+  let userObject = Users.findOne({
+    userId: userid,
+    meetingId: meetingId,
+  });
 
- // offline -> online
- if (user.connection_status !== 'online') {
- Meteor.call('validateAuthToken', meetingId, userid, authToken);
- }
- } else {
- username = 'UNKNOWN';
- }
+  if (userObject != null) {
+    logger.info('found it from the first time ' + userid);
+    if (isAllowedTo('subscribeUsers', meetingId, userid, authToken)) {
+      logger.info(`${userid} was allowed to subscribe to 'users'`);
+      const user = userObject.user;
+      if (user != null) {
+        username = user.name;
 
- Users.update({
- meetingId: meetingId,
- userId: userid,
- }, {
- $set: {
- 'user.connection_status': 'online',
- },
- });
- logger.info(`username of the subscriber: ${username}, connection_status becomes online`);
- this._session.socket.on('close', Meteor.bindEnvironment((function (_this) {
- return function () {
- logger.info(`a user lost connection: session.id=${_this._session.id} userId = ${userid}, username=${username}, meeting=${meetingId}`);
- Users.update({
- meetingId: meetingId,
- userId: userid,
- }, {
- $set: {
- 'user.connection_status': 'offline',
- },
- });
- logger.info(`username of the user losing connection: ${username}, connection_status: becomes offline`);
- return requestUserLeaving(meetingId, userid);
- };
- })(this)));
+        // offline -> online
+        if (user.connection_status !== 'online') {
+          Meteor.call('validateAuthToken', meetingId, userid, authToken);
+        }
+      } else {
+        username = 'UNKNOWN';
+      }
 
- //publish the users which are not offline
- return Users.find({
- meetingId: meetingId,
- 'user.connection_status': {
- $in: ['online', ''],
- },
- }, {
- fields: {
- authToken: false,
- },
- });
- } else {
- logger.warn("was not authorized to subscribe to 'users'");
- return this.error(new Meteor.Error(402, "The user was not authorized to subscribe to 'users'"));
- }
- } else { //subscribing before the user was added to the collection
- Meteor.call('validateAuthToken', meetingId, userid, authToken);
- logger.error(`there was no such user ${userid} in ${meetingId}`);
- return Users.find({
- meetingId: meetingId,
- 'user.connection_status': {
- $in: ['online', ''],
- },
- }, {
- fields: {
- authToken: false,
- },
- });
- }
- });
- */
+      Users.update({
+        meetingId: meetingId,
+        userId: userid,
+      }, {
+        $set: {
+          'user.connection_status': 'online',
+        },
+      });
 
-Meteor.publish('users', function (meetingId, userid, authToken) {
-  if (isAllowedTo('subscribeUsers', meetingId, userid, authToken)) {
+      logger.info(`username of the subscriber: ${username}, connection_status becomes online`);
+      this._session.socket.on('close', Meteor.bindEnvironment((function (_this) {
+        return function () {
+          logger.info(`a user lost connection: session.id=${_this._session.id}` +
+              ` userId = ${userid}, username=${username}, meeting=${meetingId}`);
+          Users.update({
+            meetingId: meetingId,
+            userId: userid,
+          }, {
+            $set: {
+              'user.connection_status': 'offline',
+            },
+          });
+
+          logger.info(`username of the user losing connection: ${username}, goes offline`);
+          return requestUserLeaving(meetingId, userid);
+        };
+      })(this)));
+
+      //publish the users which are not offline
+      return Users.find({
+        meetingId: meetingId,
+        'user.connection_status': {
+          $in: ['online', ''],
+        },
+      }, {
+        fields: {
+          authToken: false,
+        },
+      });
+    } else {
+      logger.warn("was not authorized to subscribe to 'users'");
+      return this.error(new Meteor.Error(402, "The user was not authorized to subscribe to 'users'"));
+    }
+  } else { //subscribing before the user was added to the collection
+    Meteor.call('validateAuthToken', meetingId, userid, authToken);
+    logger.error(`there was no such user ${userid} in ${meetingId}`);
     return Users.find({
       meetingId: meetingId,
       'user.connection_status': {
diff --git a/bigbluebutton-html5/imports/ui/components/app/AppService.js b/bigbluebutton-html5/imports/ui/components/app/AppService.js
index 65e8f96c70..5517b0686e 100644
--- a/bigbluebutton-html5/imports/ui/components/app/AppService.js
+++ b/bigbluebutton-html5/imports/ui/components/app/AppService.js
@@ -1,6 +1,9 @@
 import { Meteor } from 'meteor/meteor'
 import Users from '/imports/api/users/collection';
 import Polls from '/imports/api/polls/collection';
+import Chat from '/imports/api/chat/collection';
+import Meetings from '/imports/api/meetings/collection';
+import Cursor from '/imports/api/cursor/collection';
 
 let AppService = function () {
 
@@ -33,6 +36,12 @@ let AppService = function () {
     subscribeFor('shapes');
     subscribeFor('slides');
     subscribeFor('users');
+
+    window.Users = Users; // for debug purposes TODO remove
+    window.Chat = Chat; // for debug purposes TODO remove
+    window.Meetings = Meetings; // for debug purposes TODO remove
+    window.Cursor = Cursor; // for debug purposes TODO remove
+    window.Polls = Polls; // for debug purposes TODO remove
   };
 
   const subscribeFor = function (collectionName) {
@@ -51,7 +60,6 @@ let AppService = function () {
 
   let onReady = function() {
     // console.log("OnReady", Users.find().fetch());
-    window.Users = Users; // for debug purposes TODO remove
   };
   
   
-- 
GitLab