@cocreate/users 1.21.3 → 1.21.5
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 +14 -0
- package/package.json +8 -8
- package/src/server.js +140 -138
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.21.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.4...v1.21.5) (2023-05-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Simplify CoCreateUser class by adding async/await and removing unnecessary commented code. ([bd22d42](https://github.com/CoCreate-app/CoCreate-users/commit/bd22d42c6e73be130c6d208bb8010b1056e0da0a))
|
|
7
|
+
|
|
8
|
+
## [1.21.4](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.3...v1.21.4) (2023-05-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update packages to latest version. This commit updates various packages in the dependencies section of the package.json file to their latest published versions, thereby fixing multiple bugs and improving overall performance. ([57377f1](https://github.com/CoCreate-app/CoCreate-users/commit/57377f19ca386d3d1db4fd22b4a4d7a5ec4eb710))
|
|
14
|
+
|
|
1
15
|
## [1.21.3](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.2...v1.21.3) (2023-05-18)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/users",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.5",
|
|
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",
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"webpack-log": "^3.0.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cocreate/actions": "^1.8.
|
|
63
|
-
"@cocreate/crud-client": "^1.
|
|
64
|
-
"@cocreate/docs": "^1.7.
|
|
65
|
-
"@cocreate/element-prototype": "^1.8.
|
|
66
|
-
"@cocreate/form": "^1.14.
|
|
67
|
-
"@cocreate/local-storage": "^1.
|
|
68
|
-
"@cocreate/render": "^1.24.
|
|
62
|
+
"@cocreate/actions": "^1.8.11",
|
|
63
|
+
"@cocreate/crud-client": "^1.21.2",
|
|
64
|
+
"@cocreate/docs": "^1.7.11",
|
|
65
|
+
"@cocreate/element-prototype": "^1.8.11",
|
|
66
|
+
"@cocreate/form": "^1.14.11",
|
|
67
|
+
"@cocreate/local-storage": "^1.7.2",
|
|
68
|
+
"@cocreate/render": "^1.24.11"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/src/server.js
CHANGED
|
@@ -1,142 +1,144 @@
|
|
|
1
1
|
class CoCreateUser {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
2
|
+
constructor(crud) {
|
|
3
|
+
this.wsManager = crud.wsManager
|
|
4
|
+
this.crud = crud
|
|
5
|
+
this.init()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
init() {
|
|
9
|
+
if (this.wsManager) {
|
|
10
|
+
this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
|
|
11
|
+
this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
|
|
12
|
+
this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async signUp(socket, data) {
|
|
17
|
+
const self = this;
|
|
18
|
+
if (!data.document) return;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// Create new user in config db users collection
|
|
22
|
+
this.crud.createDocument(data).then((data) => {
|
|
23
|
+
if (data.document[0] && data.document[0]._id) {
|
|
24
|
+
// const orgDB = data.orgDB;
|
|
25
|
+
|
|
26
|
+
// if new orgDb Create new user in new org db users collection
|
|
27
|
+
// if (orgDB && orgDB != data.organization_id) {
|
|
28
|
+
// let Data = {...data, organization_id: orgDB}
|
|
29
|
+
// self.crud.createDocument(Data)
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
self.wsManager.broadcast(socket, 'updateDocument', data);
|
|
33
|
+
self.wsManager.send(socket, 'signUp', data);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// add new user to platformDB
|
|
37
|
+
if (data.organization_id != process.env.organization_id) {
|
|
38
|
+
let Data = { ...data, organization_id: process.env.organization_id }
|
|
39
|
+
self.crud.createDocument(Data)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// self.wsManager.broadcast(socket, 'updateUserStatus', data)
|
|
44
|
+
})
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log('createDocument error', error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
data = {
|
|
53
|
+
namespace: string,
|
|
54
|
+
collection: string,
|
|
55
|
+
data: object,
|
|
56
|
+
eId: string,
|
|
57
|
+
key: string,
|
|
58
|
+
organization_id: string
|
|
59
|
+
}
|
|
60
|
+
**/
|
|
61
|
+
async signIn(socket, data) {
|
|
62
|
+
const self = this;
|
|
63
|
+
try {
|
|
64
|
+
data.collection = 'keys'
|
|
65
|
+
this.crud.updateDocument(data).then(async (data) => {
|
|
66
|
+
let response = {
|
|
67
|
+
...data,
|
|
68
|
+
success: false,
|
|
69
|
+
message: "signIn failed",
|
|
70
|
+
status: "failed",
|
|
71
|
+
userStatus: 'off'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (data.document[0] && data.document[0]._id) {
|
|
75
|
+
let token = null;
|
|
76
|
+
if (self.wsManager.authInstance) {
|
|
77
|
+
token = await self.wsManager.authInstance.generateToken({ user_id: data.document[0]._id });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (token && token != 'null')
|
|
81
|
+
response = {
|
|
82
|
+
...response,
|
|
83
|
+
success: true,
|
|
84
|
+
message: "signIn successful",
|
|
85
|
+
status: "success",
|
|
86
|
+
userStatus: 'on',
|
|
87
|
+
token
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (data.organization_id != process.env.organization_id) {
|
|
92
|
+
let Data = { organization_id: process.env.organization_id }
|
|
93
|
+
Data.document['_id'] = data.document[0]._id
|
|
94
|
+
Data.document['lastsignIn'] = data.document[0].lastsignIn
|
|
95
|
+
Data.document['organization_id'] = process.env.organization_id
|
|
96
|
+
crud.updateDocument(Data)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
self.wsManager.send(socket, 'signIn', response)
|
|
101
|
+
self.wsManager.broadcast(socket, 'updateUserStatus', {
|
|
102
|
+
user_id: response.user_id,
|
|
103
|
+
userStatus: response.userStatus,
|
|
104
|
+
organization_id: response.organization_id
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.log('signIn failed', error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* status: 'on/off/idle'
|
|
116
|
+
*/
|
|
117
|
+
async userStatus(socket, data) {
|
|
118
|
+
const self = this;
|
|
119
|
+
try {
|
|
120
|
+
if (!data.user_id || !data.userStatus)
|
|
121
|
+
return
|
|
122
|
+
data.collection = 'users'
|
|
123
|
+
data['document'] = {
|
|
124
|
+
_id: data.user_id,
|
|
125
|
+
userStatus: data.userStatus
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.crud.updateDocument(data).then((data) => {
|
|
129
|
+
// self.wsManager.broadcast(socket, 'updateUserStatus', data)
|
|
130
|
+
self.wsManager.broadcast(socket, 'updateUserStatus', {
|
|
131
|
+
user_id: data.user_id,
|
|
132
|
+
userStatus: data.userStatus,
|
|
133
|
+
organization_id: data.organization_id || socket.config.organization_id
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.log('userStatus error')
|
|
140
|
+
}
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
module.exports = CoCreateUser;
|