@cocreate/users 1.21.7 → 1.22.1
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 +1 -1
- package/src/client.js +64 -68
- package/src/server.js +9 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.22.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.22.0...v1.22.1) (2023-05-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Remove unused function from client.js ([11fb260](https://github.com/CoCreate-app/CoCreate-users/commit/11fb2601c31e60b56b9463462dd9a44f70a797d2))
|
|
7
|
+
|
|
8
|
+
# [1.22.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.7...v1.22.0) (2023-05-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* signup create a user and userKey ([67da925](https://github.com/CoCreate-app/CoCreate-users/commit/67da925f23ebdbc4ae0e38452f6a00d020691a62))
|
|
14
|
+
|
|
1
15
|
## [1.21.7](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.6...v1.21.7) (2023-05-20)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -11,7 +11,6 @@ const CoCreateUser = {
|
|
|
11
11
|
init: function () {
|
|
12
12
|
this.initSocket();
|
|
13
13
|
this.initSession();
|
|
14
|
-
this.initChangeOrg();
|
|
15
14
|
},
|
|
16
15
|
|
|
17
16
|
initSocket: function () {
|
|
@@ -19,6 +18,67 @@ const CoCreateUser = {
|
|
|
19
18
|
crud.listen('updateUserStatus', (data) => self.updateUserStatus(data));
|
|
20
19
|
},
|
|
21
20
|
|
|
21
|
+
signUp: async function (btn) {
|
|
22
|
+
let formEl = btn.closest("form");
|
|
23
|
+
if (!formEl) return;
|
|
24
|
+
|
|
25
|
+
let organization_id = crud.socket.config.organization_id;
|
|
26
|
+
let collection = form.getAttribute('collection')
|
|
27
|
+
if (!collection) {
|
|
28
|
+
for (let el of formEl) {
|
|
29
|
+
collection = el.getAttribute('collection');
|
|
30
|
+
if (collection)
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let data = form.getData(formEl, collection)
|
|
36
|
+
data['collection'] = collection
|
|
37
|
+
data.organization_id = organization_id;
|
|
38
|
+
|
|
39
|
+
if (!data.document[0]._id)
|
|
40
|
+
data.document[0]._id = crud.ObjectId();
|
|
41
|
+
|
|
42
|
+
let user = await crud.createDocument(data)
|
|
43
|
+
form.setDocumentId(formEl, user)
|
|
44
|
+
|
|
45
|
+
// const socket = crud.socket.getSockets()
|
|
46
|
+
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
47
|
+
let key = {
|
|
48
|
+
collection: 'keys',
|
|
49
|
+
document: {
|
|
50
|
+
type: "user",
|
|
51
|
+
key: user.document[0]._id,
|
|
52
|
+
roles: ['user'],
|
|
53
|
+
email: user.document.email,
|
|
54
|
+
password: user.document.password || btoa('0000'),
|
|
55
|
+
user: {
|
|
56
|
+
collection
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
organization_id
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let response = await crud.createDocument(key)
|
|
63
|
+
if (response && response.document && response.document[0]) {
|
|
64
|
+
crud.socket.send('signUp', { user, userKey })
|
|
65
|
+
|
|
66
|
+
render.data({
|
|
67
|
+
selector: "[template='signUp']",
|
|
68
|
+
data: {
|
|
69
|
+
type: 'signUp',
|
|
70
|
+
message: 'Succesfully Signed Up',
|
|
71
|
+
success: true
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
document.dispatchEvent(new CustomEvent('signUp', {
|
|
76
|
+
detail: response
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
22
82
|
signIn: function (btn) {
|
|
23
83
|
let form = btn.closest('form');
|
|
24
84
|
let collection = form.getAttribute('collection');
|
|
@@ -117,39 +177,6 @@ const CoCreateUser = {
|
|
|
117
177
|
document.dispatchEvent(new CustomEvent('signOut'));
|
|
118
178
|
},
|
|
119
179
|
|
|
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
180
|
updateUserStatus: function (data) {
|
|
154
181
|
this.redirect(data)
|
|
155
182
|
if (data.user_id) {
|
|
@@ -207,40 +234,9 @@ const CoCreateUser = {
|
|
|
207
234
|
|
|
208
235
|
},
|
|
209
236
|
|
|
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
|
-
}
|
|
237
|
+
// TODO: updatePassword()
|
|
238
|
+
updatePassword: function (btn) {
|
|
239
|
+
this.signIn(btn);
|
|
244
240
|
}
|
|
245
241
|
};
|
|
246
242
|
|
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
|
}
|