@cocreate/users 1.5.5 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.6.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.6.1...v1.6.2) (2022-05-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * renamed usersCurrentOrg to userCurrentOrg ([3910c8a](https://github.com/CoCreate-app/CoCreate-users/commit/3910c8ad2e2e8175cc53b032aab25b184fa0492c))
7
+
8
+ ## [1.6.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.6.0...v1.6.1) (2022-05-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump cdn version to 1.14.6 ([b6db64b](https://github.com/CoCreate-app/CoCreate-users/commit/b6db64b4173dbce1c64142040ca4c43083413390))
14
+
15
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.5...v1.6.0) (2022-05-11)
16
+
17
+
18
+ ### Features
19
+
20
+ * store lastlogin datetime in db. Add demos for signup, login, logout ([7df894a](https://github.com/CoCreate-app/CoCreate-users/commit/7df894a85931c4f6c632c70429b0df72acd0867d))
21
+
1
22
  ## [1.5.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.4...v1.5.5) (2022-05-09)
2
23
 
3
24
 
@@ -0,0 +1,90 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Login | CoCreateJS</title>
5
+
6
+ <link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
7
+ <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
8
+ </head>
9
+
10
+ <body style='background-image: url("https://cdn.cocreate.app/background.png");'>
11
+ <a href="./logout.html" session="true" hidden></a>
12
+
13
+ <a href="./signup.html" title="" class="position:relative z-index:1 float:right margin:15px margin-left:auto color:white">Sign Up</a>
14
+
15
+ <div class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
16
+ <div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
17
+
18
+ <form realtime="false" collection="users" id="signin">
19
+ <div class="overflow:hidden padding:0px_25px background:white">
20
+ <div class="float:left width:75% padding-top:25px">
21
+ <h3>Sign In</h3>
22
+ </div>
23
+ <div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
24
+ <i class="fas fa-sign-in-alt"></i>
25
+ </div>
26
+ </div>
27
+ <div class="padding:25px background:gainsboro text-align:left">
28
+
29
+ <floating-label>
30
+ <input type="email" name='email' placeholder="Email" class="floating-label">
31
+ </floating-label>
32
+
33
+ <floating-label>
34
+ <input type="password" name='password' placeholder="Password" class="floating-label">
35
+ </floating-label>
36
+
37
+ <button actions="login" href="logout.html" class="outline">Login</button>
38
+
39
+ <a show='#forgotpass' hide='#signin'>Forgot Password</a>
40
+ </div>
41
+ </form>
42
+
43
+ <form collection="users" hidden id="forgotpass">
44
+ <div class="overflow:hidden padding:0px_25px background:white">
45
+ <div class="float:left width:75% padding-top:25px">
46
+ <h3>Password Recovery</h3>
47
+ </div>
48
+ <div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
49
+ <i class="fas fa-key"></i>
50
+ </div>
51
+ </div>
52
+ <div class="padding:25px background:gainsboro text-align:left">
53
+ <floating-label>
54
+ <input type="email" name='email' id="email" placeholder="Email" class="floating-label">
55
+ </floating-label>
56
+
57
+ <button class="outline">
58
+ <a>Send Email</a>
59
+ </button>
60
+
61
+ <a show='#signin' hide='#forgotpass'>login</a>
62
+ </div>
63
+ </form>
64
+
65
+ </div>
66
+ </div>
67
+
68
+ <div class="position:fixed!important bottom:15px right:15px">
69
+ <div template_id="login" class="template card margin:5px padding:10px {{status}}">
70
+ <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
71
+ </div>
72
+
73
+ <div template_id="notification" class="template card position:fixed!important bottom:15px right:15px padding:10px {{status}}">
74
+ <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
75
+ </div>
76
+ </div>
77
+
78
+ <script>
79
+ var config = {
80
+ apiKey: '2061acef-0451-4545-f754-60cf8160', // Your apiKey can be retrived after signing up at https://cocreate.app
81
+ organization_id: '5ff747727005da1c272740ab', // Your organization_id can be retrived after signing up at https://cocreate.app
82
+ host: 'server.cocreate.app' // Points to socket server. If not defined it will use the url in web browser by default
83
+ }
84
+ </script>
85
+
86
+ <script src="https://cdn.cocreate.app/1.14.6/CoCreate.min.js"></script>
87
+ <!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
88
+
89
+ </body>
90
+ </html>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Logout | CoCreateJS</title>
5
+
6
+ <link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
7
+ <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
8
+ </head>
9
+
10
+ <body style='background-image: url("https://cdn.cocreate.app/background.png");'>
11
+ <a href="./login.html" session="false" hidden></a>
12
+
13
+ <div class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
14
+ <div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
15
+ <div class="overflow:hidden padding:0px_25px background:white">
16
+ <div class="float:left width:75% padding-top:25px">
17
+ <h3>You are logged in</h3>
18
+ </div>
19
+ <div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
20
+ <i class="fas fa-sign-in-alt"></i>
21
+ </div>
22
+ </div>
23
+ <div class="padding:25px background:gainsboro text-align:left">
24
+ <button actions="logout" href="./login.html">Logout</button>
25
+ </div>
26
+ </div>
27
+ </div>
28
+
29
+ <div class="position:fixed!important bottom:15px right:15px">
30
+ <div template_id="notification" class="template card position:fixed!important bottom:15px right:15px padding:10px {{status}}">
31
+ <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
32
+ </div>
33
+ </div>
34
+
35
+ <script src="https://cdn.cocreate.app/1.14.6/CoCreate.min.js"></script>
36
+ <!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
37
+
38
+ </body>
39
+ </html>
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <title>Sign up | CoCreate</title>
9
+ <link rel="icon" type="image/png" sizes="32x32" href="assets/favicon.ico">
10
+ <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
11
+ </head>
12
+
13
+ <style>
14
+ .speech-bubble:after { content: ''; position: absolute; top: 0; left: 50%; width: 0; height: 0; border: 23px solid transparent; border-bottom-color: #ffffff; border-top: 0; margin-left: -23px; margin-top: -23px;}
15
+ </style>
16
+
17
+ <body style='background: url("https://cdn.cocreate.app/background.png") no-repeat fixed;-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;'>
18
+ <a href="./index.html" session="true" hidden></a>
19
+
20
+ <a href="./signin.html" title="" class="position:relative z-index:1 float:right margin:15px margin-left:auto color:white">Sign In</a>
21
+
22
+ <main class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
23
+ <div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
24
+
25
+ <form realtime="false" autocomplete="off">
26
+
27
+ <section>
28
+ <div class="overflow:hidden padding:0px_25px background:white">
29
+ <div class="float:left width:75% padding-top:25px">
30
+ <h3>Sign UP</h3>
31
+ </div>
32
+ <div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
33
+ <i class="fa fa-key"></i>
34
+ </div>
35
+ </div>
36
+ <div class="padding:25px background:gainsboro text-align:left">
37
+ <floating-label>
38
+ <input type="text" id="name"
39
+ collection="users"
40
+ document_id=""
41
+ name="name"
42
+ placeholder="Full Name"
43
+ class="floating-label"
44
+ autocomplete="off"
45
+ required>
46
+ </floating-label>
47
+ <floating-label>
48
+ <input type="email" id="email"
49
+ collection="users"
50
+ unique
51
+ document_id=""
52
+ name='email'
53
+ placeholder="Email"
54
+ class="floating-label"
55
+ required>
56
+ </floating-label>
57
+ <small id="errorUemail" class="text-danger"></small>
58
+
59
+ <floating-label>
60
+ <input type="password" id="password"
61
+ collection="users"
62
+ document_id=""
63
+ name="password"
64
+ placeholder="Password"
65
+ class="floating-label">
66
+ </floating-label>
67
+ <small id="errorUpassword" class="text-danger"></small>
68
+
69
+ <floating-label>
70
+ <input type="password"
71
+ matches="#password"
72
+ placeholder="Confirm Password"
73
+ class="floating-label">
74
+ </floating-label>
75
+ <small id="errorUconfirmpassword" class="text-danger"></small>
76
+
77
+ <div class="display:flex">
78
+ <button type="button" class="outline red-white startAnimation" actions="validate, createUser, login" href="logout.html">
79
+ Sign Up
80
+ </button>
81
+ </div>
82
+
83
+ </div>
84
+ </section>
85
+ </form>
86
+ </div>
87
+ </main>
88
+
89
+ <div class="position:fixed!important bottom:15px right:15px">
90
+ <div template_id="validate" class="template card margin:5px padding:10px {{status}}">
91
+ <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
92
+ </div>
93
+
94
+ <div template_id="notification" class="template card margin:5px padding:10px {{status}}">
95
+ <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
96
+ </div>
97
+ </div>
98
+
99
+ <script>
100
+ var config = {
101
+ apiKey: '2061acef-0451-4545-f754-60cf8160', // Your apiKey can be retrived after signing up at https://cocreate.app
102
+ organization_id: '5ff747727005da1c272740ab', // Your organization_id can be retrived after signing up at https://cocreate.app
103
+ host: 'server.cocreate.app' // Points to socket server. If not defined it will use the url in web browser by default
104
+ }
105
+ </script>
106
+ <script src="https://cdn.cocreate.app/1.14.6/CoCreate.min.js"></script>
107
+ <!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
108
+
109
+ </body>
110
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.5.5",
3
+ "version": "1.6.2",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
package/src/client.js CHANGED
@@ -34,18 +34,13 @@ const CoCreateUser = {
34
34
  detail: data
35
35
  }));
36
36
  });
37
- crud.listen('createUserNew', function(data) {
38
- document.dispatchEvent(new CustomEvent('createUserNew', {
39
- detail: data
40
- }));
41
- });
42
37
  crud.listen('fetchedUser', this.checkPermissions);
43
- crud.listen('login', (instance) => self.loginResult(instance));
44
- crud.listen('changedUserStatus', this.changedUserStatus);
45
- crud.listen('usersCurrentOrg', (instance) => self.setCurrentOrg(instance));
38
+ crud.listen('login', (instance) => self.loginResponse(instance));
39
+ crud.listen('updateUserStatus', this.updateUserStatus);
40
+ crud.listen('userCurrentOrg', (instance) => self.setCurrentOrg(instance));
46
41
  },
47
42
 
48
- requestLogin: function(btn) {
43
+ loginRequest: function(btn) {
49
44
  let form = btn.closest('form');
50
45
  let collection = form.getAttribute('collection');
51
46
  let loginData = {};
@@ -74,17 +69,17 @@ const CoCreateUser = {
74
69
  });
75
70
  },
76
71
 
77
- loginResult: function(data) {
72
+ loginResponse: function(data) {
78
73
  let { success, status, message, token } = data;
79
74
 
80
75
  if (success) {
81
76
  window.localStorage.setItem('organization_id', window.config.organization_id);
82
77
  window.localStorage.setItem("apiKey", window.config.apiKey);
83
78
  window.localStorage.setItem("host", window.config.host);
84
- window.localStorage.setItem('user_id', data['id']);
79
+ window.localStorage.setItem('user_id', data['document_id']);
85
80
  window.localStorage.setItem("token", token);
86
81
  document.cookie = `token=${token};path=/`;
87
- this.getCurrentOrg(data['id'], data['collection']);
82
+ this.getCurrentOrg(data['document_id'], data['collection']);
88
83
  message = "Succesful Login";
89
84
  document.dispatchEvent(new CustomEvent('login', {
90
85
  detail: {}
@@ -105,7 +100,7 @@ const CoCreateUser = {
105
100
  },
106
101
 
107
102
  getCurrentOrg: function(user_id, collection) {
108
- crud.send('usersCurrentOrg', {
103
+ crud.send('userCurrentOrg', {
109
104
  "apiKey": window.config.apiKey,
110
105
  "organization_id": window.config.organization_id,
111
106
  "collection": collection || 'users',
@@ -229,7 +224,7 @@ const CoCreateUser = {
229
224
  });
230
225
  },
231
226
 
232
- changedUserStatus: (data) => {
227
+ updateUserStatus: (data) => {
233
228
  if (!data.user_id) {
234
229
  return;
235
230
  }
@@ -254,24 +249,6 @@ const CoCreateUser = {
254
249
  }
255
250
  },
256
251
 
257
- createUserNew: function(btn) {
258
- let form = btn.closest("form");
259
- if (!form) return;
260
- let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
261
- let user_id = form.querySelector("input[collection='users'][name='_id']");
262
-
263
- const room = config.organization_id;
264
-
265
- crud.send('createUserNew', {
266
- apiKey: config.apiKey,
267
- organization_id: config.organization_id,
268
- collection: 'users',
269
- newOrg_id: org_id,
270
- user_id: user_id,
271
- }, room);
272
-
273
- },
274
-
275
252
  createUser: function(btn) {
276
253
  let form = btn.closest("form");
277
254
  if (!form) return;
@@ -279,9 +256,11 @@ const CoCreateUser = {
279
256
  let elements = form.querySelectorAll("[collection='users'][name]");
280
257
  let orgIdElement = form.querySelector("input[collection='organizations'][name='_id']");
281
258
 
282
- if (orgIdElement) {
259
+ if (orgIdElement)
283
260
  org_id = orgIdElement.value;
284
- }
261
+ else
262
+ org_id = config.organization_id;
263
+
285
264
  let data = {};
286
265
  //. get form data
287
266
  elements.forEach(el => {
@@ -311,14 +290,6 @@ const CoCreateUser = {
311
290
  };
312
291
 
313
292
 
314
- action.init({
315
- name: "createUserNew",
316
- endEvent: "createUserNew",
317
- callback: (btn, data) => {
318
- CoCreateUser.createUser(btn);
319
- },
320
- });
321
-
322
293
  action.init({
323
294
  name: "createUser",
324
295
  endEvent: "createUser",
@@ -331,7 +302,7 @@ action.init({
331
302
  name: "login",
332
303
  endEvent: "login",
333
304
  callback: (btn, data) => {
334
- CoCreateUser.requestLogin(btn, data);
305
+ CoCreateUser.loginRequest(btn, data);
335
306
  },
336
307
  });
337
308
 
package/src/server.js CHANGED
@@ -9,47 +9,14 @@ class CoCreateUser {
9
9
 
10
10
  init() {
11
11
  if (this.wsManager) {
12
- this.wsManager.on('createUserNew', (socket, data, socketInfo) => this.createUserNew(socket, data));
13
- this.wsManager.on('createUser', (socket, data, socketInfo) => this.createUser(socket, data));
12
+ this.wsManager.on('createUser', (socket, data, socketInfo) => this.createUser(socket, data, socketInfo));
14
13
  this.wsManager.on('login', (socket, data, socketInfo) => this.login(socket, data, socketInfo))
15
- this.wsManager.on('usersCurrentOrg', (socket, data, socketInfo) => this.usersCurrentOrg(socket, data, socketInfo))
16
- this.wsManager.on('fetchUser', (socket, data, socketInfo) => this.fetchUser(socket, data, socketInfo))
17
- this.wsManager.on('userStatus', (socket, data, socketInfo) => this.setUserStatus(socket, data, socketInfo))
14
+ this.wsManager.on('userCurrentOrg', (socket, data, socketInfo) => this.userCurrentOrg(socket, data, socketInfo))
15
+ this.wsManager.on('userStatus', (socket, data, socketInfo) => this.userStatus(socket, data, socketInfo))
18
16
  }
19
17
  }
20
18
 
21
-
22
- async createUserNew(socket, data) {
23
- const self = this;
24
- if(!data) return;
25
- const newOrg_id = data.newOrg_id;
26
- if (newOrg_id != data.organization_id) {
27
- try{
28
- const db = this.dbClient.db(req_data['organization_id']);
29
- const collection = db.collection(req_data["collection"]);
30
- const query = {
31
- "_id": new ObjectId(data["user_id"])
32
- };
33
-
34
- collection.find(query).toArray(function(error, result) {
35
- if(!error && result){
36
- const newOrgDb = self.dbClient.db(newOrg_id).collection(data['collection']);
37
- // Create new user in config db users collection
38
- newOrgDb.insertOne({...result.ops[0], organization_id : newOrg_id}, function(error, result) {
39
- if(!error && result){
40
- const response = { ...data, document_id: `${result.insertedId}`, data: result.ops[0]}
41
- self.wsManager.send(socket, 'createUserNew', response, data['organization_id']);
42
- }
43
- });
44
- }
45
- });
46
- }catch(error){
47
- console.log('createDocument error', error);
48
- }
49
- }
50
- }
51
-
52
- async createUser(socket, data) {
19
+ async createUser(socket, data, socketInfo) {
53
20
  const self = this;
54
21
  if(!data.data) return;
55
22
 
@@ -61,14 +28,12 @@ class CoCreateUser {
61
28
  const orgDB = data.orgDB;
62
29
  data.data['_id'] = result.insertedId;
63
30
  // if new orgDb Create new user in new org db users collection
64
- if (orgDB != data.organization_id) {
65
- if (orgDB) {
66
- const anotherCollection = self.dbClient.db(orgDB).collection(data['collection']);
67
- anotherCollection.insertOne({...data.data, organization_id : orgDB});
68
- }
31
+ if (orgDB && orgDB != data.organization_id) {
32
+ const anotherCollection = self.dbClient.db(orgDB).collection(data['collection']);
33
+ anotherCollection.insertOne({...data.data, organization_id : orgDB});
69
34
  }
70
35
  const response = { ...data, document_id: `${result.insertedId}`}
71
- self.wsManager.send(socket, 'createUser', response, data['organization_id']);
36
+ self.wsManager.send(socket, 'createUser', response, socketInfo);
72
37
 
73
38
  // add new user to platformDB
74
39
  if (data.organization_id != process.env.organization_id) {
@@ -89,55 +54,59 @@ class CoCreateUser {
89
54
  collection: string,
90
55
  loginData: object,
91
56
  eId: string,
92
- form_id: string,
93
57
 
94
58
  apiKey: string,
95
59
  organization_id: string
96
60
  }
97
61
  **/
98
- async login(socket, req_data) {
62
+ async login(socket, data, socketInfo) {
99
63
  const self = this;
100
64
  try {
101
- const {organization_id} = req_data
65
+ const {organization_id} = data
102
66
  const selectedDB = organization_id;
103
- const collection = self.dbClient.db(selectedDB).collection(req_data["collection"]);
67
+ const collection = self.dbClient.db(selectedDB).collection(data["collection"]);
104
68
  const query = new Object();
105
69
 
106
- // query['connected_orgs'] = data['organization_id'];
107
-
108
- for (var key in req_data['loginData']) {
109
- query[key] = req_data['loginData'][key];
70
+ for (var key in data['loginData']) {
71
+ query[key] = data['loginData'][key];
110
72
  }
111
73
 
112
- collection.find(query).toArray(async function(error, result) {
74
+ collection.findOneAndUpdate(query, {$set: {lastLogin: new Date()}}, async function(error, result) {
113
75
  let response = {
114
- eId: req_data['eId'],
115
- uid: req_data['uid'],
116
- form_id: req_data['form_id'],
117
76
  success: false,
118
77
  message: "Login failed",
119
- status: "failed"
78
+ status: "failed",
79
+ uid: data['uid']
120
80
  }
121
- if (!error && result && result.length > 0) {
81
+ if (!error && result && result.value) {
122
82
  let token = null;
123
83
  if (self.wsManager.authInstance) {
124
- console.log('login user_id: ', `${result[0]['_id']}`)
125
- token = await self.wsManager.authInstance.generateToken({user_id: `${result[0]['_id']}`});
84
+ token = await self.wsManager.authInstance.generateToken({user_id: `${result.value['_id']}`});
85
+ }
86
+
87
+ if (token && token != 'null')
88
+ response = { ...response,
89
+ success: true,
90
+ collection: data["collection"],
91
+ document_id: result.value['_id'],
92
+ current_org: result.value['current_org'],
93
+ message: "Login successful",
94
+ status: "success",
95
+ token
96
+ };
97
+
98
+ let user_id = response.document_id;
99
+ const query = {
100
+ "_id": new ObjectId(user_id),
126
101
  }
127
102
 
128
- response = { ...response,
129
- success: true,
130
- id: result[0]['_id'],
131
- // collection: collection,
132
- document_id: result[0]['_id'],
133
- current_org: result[0]['current_org'],
134
- message: "Login successful",
135
- status: "success",
136
- token
137
- };
103
+ if (data.organization_id != process.env.organization_id) {
104
+ const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
105
+ platformDB.updateOne(query, {$set: {lastLogin: new Date()}})
106
+ }
138
107
  }
139
- self.wsManager.send(socket, 'login', response, req_data['organization_id'])
140
- console.log('success socket', req_data['organization_id']);
108
+ self.wsManager.send(socket, 'login', response, socketInfo)
109
+ console.log(`${response.message} user_id: ${result.value['_id']}`)
141
110
  });
142
111
  } catch (error) {
143
112
  console.log('login failed', error);
@@ -152,16 +121,16 @@ class CoCreateUser {
152
121
  href: string
153
122
  }
154
123
  **/
155
- async usersCurrentOrg(socket, req_data) {
124
+ async userCurrentOrg(socket, data, socketInfo) {
156
125
  try {
157
126
  const self = this;
158
- const {organization_id, db} = req_data
127
+ const {organization_id, db} = data
159
128
  const selectedDB = db || organization_id;
160
- const collection = this.dbClient.db(selectedDB).collection(req_data["collection"]);
129
+ const collection = this.dbClient.db(selectedDB).collection(data["collection"]);
161
130
 
162
131
  let query = new Object();
163
132
 
164
- query['_id'] = new ObjectId(req_data['user_id']);
133
+ query['_id'] = new ObjectId(data['user_id']);
165
134
 
166
135
  collection.find(query).toArray(function(error, result) {
167
136
 
@@ -173,21 +142,20 @@ class CoCreateUser {
173
142
 
174
143
  orgCollection.find({"_id": new ObjectId(org_id),}).toArray(function(err, res) {
175
144
  if (!err && res && res.length > 0) {
176
- self.wsManager.send(socket, 'usersCurrentOrg', {
177
- id: req_data['id'],
178
- uid: req_data['uid'],
145
+ self.wsManager.send(socket, 'userCurrentOrg', {
179
146
  success: true,
180
147
  user_id: result[0]['_id'],
181
148
  current_org: result[0]['current_org'],
182
149
  apiKey: res[0]['apiKey'],
183
- href: req_data['href']
184
- }, req_data['organization_id'])
150
+ href: data['href'],
151
+ uid: data['uid']
152
+ }, socketInfo)
185
153
  }
186
154
  });
155
+
187
156
  }
188
157
  } else {
189
158
  // socket.emit('loginResult', {
190
- // form_id: data['form_id'],
191
159
  // success: false
192
160
  // });
193
161
  }
@@ -197,44 +165,13 @@ class CoCreateUser {
197
165
  }
198
166
  }
199
167
 
200
- /**
201
- data = {
202
- namespace: string,
203
- collection: string,
204
- user_id: object,
205
-
206
- apiKey: string,
207
- organization_id: string
208
- }
209
- **/
210
- async fetchUser(socket, req_data) {
211
- const self = this;
212
-
213
- try {
214
- const {organization_id, db} = req_data
215
- const selectedDB = db || organization_id;
216
- const collection = self.dbClient.db(selectedDB).collection(req_data['collection']);
217
- const user_id = req_data['user_id'];
218
- const query = {
219
- "_id": new ObjectId(user_id),
220
- }
221
-
222
- collection.findOne(query, function(error, result) {
223
- if (!error) {
224
- self.wsManager.send(socket, 'fetchedUser', result, req_data['organization_id']);
225
- }
226
- })
227
- } catch (error) {
228
- console.log('fetchUser error')
229
- }
230
- }
231
168
 
232
169
  /**
233
170
  * status: 'on/off/idle'
234
171
  */
235
- async setUserStatus(socket, req_data, socketInfo) {
172
+ async userStatus(socket, data, socketInfo) {
236
173
  const self = this;
237
- const {info, status} = req_data;
174
+ const {info, status} = data;
238
175
 
239
176
  const items = info.split('/');
240
177
 
@@ -245,24 +182,26 @@ class CoCreateUser {
245
182
  if (!items[1]) return;
246
183
 
247
184
  try {
248
- const {organization_id, db} = req_data
185
+ const {organization_id, db} = data
249
186
  const selectedDB = db || organization_id;
250
187
  const collection = self.dbClient.db(selectedDB).collection('users');
251
188
  const user_id = items[1];
252
189
  const query = {
253
190
  "_id": new ObjectId(user_id),
254
191
  }
255
- collection.update(query, {$set: {status: status}}, function(err, res) {
192
+ collection.updateOne(query, {$set: {status: status}}, function(err, res) {
256
193
  if (!err) {
257
- self.wsManager.broadcast(socket, '', null, 'changedUserStatus',
194
+ self.wsManager.broadcast(socket, '', null, 'updateUserStatus',
258
195
  {
259
196
  user_id,
260
197
  status
261
- })
198
+ }, socketInfo)
262
199
  }
200
+ else
201
+ console.log('err', err)
263
202
  })
264
203
  } catch (error) {
265
- console.log('fetchUser error')
204
+ console.log('userStatus error')
266
205
  }
267
206
  }
268
207
  }
package/demo/index.html DELETED
@@ -1,25 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <title>Users | CoCreateJS</title>
5
-
6
- <!-- CoCreate Favicon -->
7
- <link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
8
- <!-- CoCreate CSS CDN -->
9
- <link rel="stylesheet" href="https://cdn.cocreate.app/action/latest/CoCreate-action.min.css" type="text/css" />
10
- </head>
11
- <body>
12
-
13
- <script>
14
- var config = {
15
- apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
16
- organization_id: '5de0387b12e200ea63204d6c',
17
- host: 'ws.cocreate.app'
18
- }
19
- </script>
20
-
21
- <!--<script src="../dist/CoCreate-users.js"></script>-->
22
- <script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
23
-
24
- </body>
25
- </html>