@cocreate/users 1.21.6 → 1.22.0
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 +2 -2
- package/src/client.js +64 -67
- package/src/server.js +9 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.22.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.7...v1.22.0) (2023-05-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* signup create a user and userKey ([67da925](https://github.com/CoCreate-app/CoCreate-users/commit/67da925f23ebdbc4ae0e38452f6a00d020691a62))
|
|
7
|
+
|
|
8
|
+
## [1.21.7](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.6...v1.21.7) (2023-05-20)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* updated dependencies to their latest versions ([2807bb2](https://github.com/CoCreate-app/CoCreate-users/commit/2807bb28f7845959ffd0f70fea7b0b502f033da1))
|
|
14
|
+
|
|
1
15
|
## [1.21.6](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.5...v1.21.6) (2023-05-20)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/users",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
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",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@cocreate/actions": "^1.8.11",
|
|
63
|
-
"@cocreate/crud-client": "^1.21.
|
|
63
|
+
"@cocreate/crud-client": "^1.21.3",
|
|
64
64
|
"@cocreate/docs": "^1.7.11",
|
|
65
65
|
"@cocreate/element-prototype": "^1.8.11",
|
|
66
66
|
"@cocreate/form": "^1.14.11",
|
package/src/client.js
CHANGED
|
@@ -19,6 +19,67 @@ const CoCreateUser = {
|
|
|
19
19
|
crud.listen('updateUserStatus', (data) => self.updateUserStatus(data));
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
+
signUp: async function (btn) {
|
|
23
|
+
let formEl = btn.closest("form");
|
|
24
|
+
if (!formEl) return;
|
|
25
|
+
|
|
26
|
+
let organization_id = crud.socket.config.organization_id;
|
|
27
|
+
let collection = form.getAttribute('collection')
|
|
28
|
+
if (!collection) {
|
|
29
|
+
for (let el of formEl) {
|
|
30
|
+
collection = el.getAttribute('collection');
|
|
31
|
+
if (collection)
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let data = form.getData(formEl, collection)
|
|
37
|
+
data['collection'] = collection
|
|
38
|
+
data.organization_id = organization_id;
|
|
39
|
+
|
|
40
|
+
if (!data.document[0]._id)
|
|
41
|
+
data.document[0]._id = crud.ObjectId();
|
|
42
|
+
|
|
43
|
+
let user = await crud.createDocument(data)
|
|
44
|
+
form.setDocumentId(formEl, user)
|
|
45
|
+
|
|
46
|
+
// const socket = crud.socket.getSockets()
|
|
47
|
+
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
48
|
+
let key = {
|
|
49
|
+
collection: 'keys',
|
|
50
|
+
document: {
|
|
51
|
+
type: "user",
|
|
52
|
+
key: user.document[0]._id,
|
|
53
|
+
roles: ['user'],
|
|
54
|
+
email: user.document.email,
|
|
55
|
+
password: user.document.password || btoa('0000'),
|
|
56
|
+
user: {
|
|
57
|
+
collection
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
organization_id
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let response = await crud.createDocument(key)
|
|
64
|
+
if (response && response.document && response.document[0]) {
|
|
65
|
+
crud.socket.send('signUp', { user, userKey })
|
|
66
|
+
|
|
67
|
+
render.data({
|
|
68
|
+
selector: "[template='signUp']",
|
|
69
|
+
data: {
|
|
70
|
+
type: 'signUp',
|
|
71
|
+
message: 'Succesfully Signed Up',
|
|
72
|
+
success: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
document.dispatchEvent(new CustomEvent('signUp', {
|
|
77
|
+
detail: response
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
22
83
|
signIn: function (btn) {
|
|
23
84
|
let form = btn.closest('form');
|
|
24
85
|
let collection = form.getAttribute('collection');
|
|
@@ -117,39 +178,6 @@ const CoCreateUser = {
|
|
|
117
178
|
document.dispatchEvent(new CustomEvent('signOut'));
|
|
118
179
|
},
|
|
119
180
|
|
|
120
|
-
signUp: function (btn) {
|
|
121
|
-
let formEl = btn.closest("form");
|
|
122
|
-
if (!formEl) return;
|
|
123
|
-
|
|
124
|
-
let organization_id = crud.socket.config.organization_id;
|
|
125
|
-
let data = form.getData(formEl, 'users')
|
|
126
|
-
data['collection'] = 'users'
|
|
127
|
-
// data.document['current_org'] = organization_id;
|
|
128
|
-
// data.document['connected_orgs'] = [organization_id];
|
|
129
|
-
data.organization_id = [organization_id];
|
|
130
|
-
|
|
131
|
-
// const socket = crud.socket.getSockets()
|
|
132
|
-
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
133
|
-
// TODO: can use updateDocument with filter query
|
|
134
|
-
crud.createDocument(data).then((response) => {
|
|
135
|
-
form.setDocumentId(formEl, response)
|
|
136
|
-
|
|
137
|
-
render.data({
|
|
138
|
-
selector: "[template='signUp']",
|
|
139
|
-
data: {
|
|
140
|
-
type: 'signUp',
|
|
141
|
-
message: 'Succesfully Signed Up',
|
|
142
|
-
success: true
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
document.dispatchEvent(new CustomEvent('signUp', {
|
|
147
|
-
detail: response
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
},
|
|
152
|
-
|
|
153
181
|
updateUserStatus: function (data) {
|
|
154
182
|
this.redirect(data)
|
|
155
183
|
if (data.user_id) {
|
|
@@ -207,40 +235,9 @@ const CoCreateUser = {
|
|
|
207
235
|
|
|
208
236
|
},
|
|
209
237
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (!user_id) return;
|
|
214
|
-
|
|
215
|
-
let orgChangers = document.querySelectorAll('.org-changer');
|
|
216
|
-
|
|
217
|
-
for (let i = 0; i < orgChangers.length; i++) {
|
|
218
|
-
let orgChanger = orgChangers[i];
|
|
219
|
-
|
|
220
|
-
const collection = orgChanger.getAttribute('collection');
|
|
221
|
-
const id = orgChanger.getAttribute('document_id');
|
|
222
|
-
|
|
223
|
-
if (collection == 'users' && id == user_id) {
|
|
224
|
-
orgChanger.addEventListener('selected', function (e) {
|
|
225
|
-
// TODO: can get selected value from event/element, readDocument not required.
|
|
226
|
-
crud.readDocument({
|
|
227
|
-
collection: collection || 'users',
|
|
228
|
-
document: {
|
|
229
|
-
_id: user_id
|
|
230
|
-
},
|
|
231
|
-
}).then((data) => {
|
|
232
|
-
localStorage.setItem('key', data['key']);
|
|
233
|
-
localStorage.setItem('organization_id', data.document[0]['current_org']);
|
|
234
|
-
localStorage.setItem('host', crud.socket.config.host);
|
|
235
|
-
|
|
236
|
-
document.dispatchEvent(new CustomEvent('signIn'));
|
|
237
|
-
window.location.reload();
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
238
|
+
// TODO: updatePassword()
|
|
239
|
+
updatePassword: function (btn) {
|
|
240
|
+
this.signIn(btn);
|
|
244
241
|
}
|
|
245
242
|
};
|
|
246
243
|
|
package/src/server.js
CHANGED
|
@@ -15,33 +15,20 @@ class CoCreateUser {
|
|
|
15
15
|
|
|
16
16
|
async signUp(socket, data) {
|
|
17
17
|
const self = this;
|
|
18
|
-
if (!data.document) return;
|
|
19
|
-
|
|
20
18
|
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
19
|
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
if (data.user) {
|
|
21
|
+
const response = await this.crud.createDocument(data.user)
|
|
22
|
+
this.wsManager.broadcast(socket, 'createDocument', response);
|
|
23
|
+
}
|
|
34
24
|
|
|
25
|
+
if (data.userKey) {
|
|
26
|
+
const response = await this.crud.createDocument(data.userKey)
|
|
27
|
+
this.wsManager.broadcast(socket, 'createDocument', response);
|
|
28
|
+
}
|
|
35
29
|
|
|
36
|
-
|
|
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
|
-
}
|
|
30
|
+
self.wsManager.send(socket, 'signUp', data);
|
|
42
31
|
|
|
43
|
-
// self.wsManager.broadcast(socket, 'updateUserStatus', data)
|
|
44
|
-
})
|
|
45
32
|
} catch (error) {
|
|
46
33
|
console.log('createDocument error', error);
|
|
47
34
|
}
|