@cocreate/users 1.20.0 → 1.21.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 +15 -0
- package/CoCreate.config.js +1 -1
- package/package.json +2 -1
- package/src/client.js +33 -94
- package/src/server.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.21.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.0...v1.21.1) (2023-05-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* apikey renamed to key ([392ec35](https://github.com/CoCreate-app/CoCreate-users/commit/392ec35a1d5b0234a30cd5342ea6b6dfd0d59b05))
|
|
7
|
+
* apikey renamed to key ([f195cc7](https://github.com/CoCreate-app/CoCreate-users/commit/f195cc726e448b45e3e94ec8ee15af105840c9ba))
|
|
8
|
+
|
|
9
|
+
# [1.21.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.20.0...v1.21.0) (2023-05-10)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* added @cocreate/form ([2fb6c2b](https://github.com/CoCreate-app/CoCreate-users/commit/2fb6c2b635f7bb6cc7d527f0d6c439eaa95cf19d))
|
|
15
|
+
|
|
1
16
|
# [1.20.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.19.9...v1.20.0) (2023-05-10)
|
|
2
17
|
|
|
3
18
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/users",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
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",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@cocreate/crud-client": "^1.20.4",
|
|
64
64
|
"@cocreate/docs": "^1.7.8",
|
|
65
65
|
"@cocreate/element-prototype": "^1.8.7",
|
|
66
|
+
"@cocreate/form": "^1.14.6",
|
|
66
67
|
"@cocreate/local-storage": "^1.6.8",
|
|
67
68
|
"@cocreate/render": "^1.24.8"
|
|
68
69
|
}
|
package/src/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*globals CustomEvent, btoa*/
|
|
2
2
|
import crud from '@cocreate/crud-client';
|
|
3
3
|
import action from '@cocreate/actions';
|
|
4
|
+
import form from '@cocreate/form';
|
|
4
5
|
import render from '@cocreate/render';
|
|
5
6
|
import '@cocreate/element-prototype';
|
|
6
7
|
import './index.css';
|
|
@@ -15,24 +16,6 @@ const CoCreateUser = {
|
|
|
15
16
|
|
|
16
17
|
initSocket: function() {
|
|
17
18
|
const self = this;
|
|
18
|
-
// crud.listen('signUp', function(data) {
|
|
19
|
-
// self.setDocumentId('users', data.document[0]._id);
|
|
20
|
-
|
|
21
|
-
// render.data({
|
|
22
|
-
// selector: "[template='signUp']",
|
|
23
|
-
// data: {
|
|
24
|
-
// type: 'signUp',
|
|
25
|
-
// message: 'Succesfully Signed Up',
|
|
26
|
-
// success: true
|
|
27
|
-
// }
|
|
28
|
-
// });
|
|
29
|
-
|
|
30
|
-
// document.dispatchEvent(new CustomEvent('signUp', {
|
|
31
|
-
// detail: data
|
|
32
|
-
// }));
|
|
33
|
-
// });
|
|
34
|
-
|
|
35
|
-
crud.listen('signIn', (data) => self.signInResponse(data));
|
|
36
19
|
crud.listen('updateUserStatus', (data) => self.updateUserStatus(data));
|
|
37
20
|
},
|
|
38
21
|
|
|
@@ -45,12 +28,8 @@ const CoCreateUser = {
|
|
|
45
28
|
|
|
46
29
|
inputs.forEach((input) => {
|
|
47
30
|
const name = input.getAttribute('name');
|
|
48
|
-
|
|
49
|
-
if (input.type == 'password') {
|
|
50
|
-
value = btoa(value);
|
|
51
|
-
}
|
|
31
|
+
const value = input.getValue();
|
|
52
32
|
collection = input.getAttribute('collection') || collection;
|
|
53
|
-
|
|
54
33
|
query.push({name, value, operator: '$eq'})
|
|
55
34
|
});
|
|
56
35
|
|
|
@@ -79,9 +58,10 @@ const CoCreateUser = {
|
|
|
79
58
|
}
|
|
80
59
|
})
|
|
81
60
|
} else {
|
|
82
|
-
// ToDo: can be depreciated if we have another means of token generation
|
|
83
61
|
request.broadcastBrowser = false
|
|
84
|
-
crud.socket.send('signIn', request)
|
|
62
|
+
crud.socket.send('signIn', request).then((response) => {
|
|
63
|
+
this.signInResponse(data)
|
|
64
|
+
})
|
|
85
65
|
}
|
|
86
66
|
},
|
|
87
67
|
|
|
@@ -90,7 +70,7 @@ const CoCreateUser = {
|
|
|
90
70
|
|
|
91
71
|
if (success) {
|
|
92
72
|
localStorage.setItem('organization_id', crud.socket.config.organization_id);
|
|
93
|
-
localStorage.setItem("
|
|
73
|
+
localStorage.setItem("key", crud.socket.config.key);
|
|
94
74
|
localStorage.setItem("host", crud.socket.config.host);
|
|
95
75
|
localStorage.setItem('user_id', data.document[0]['_id']);
|
|
96
76
|
localStorage.setItem("token", token);
|
|
@@ -139,61 +119,36 @@ const CoCreateUser = {
|
|
|
139
119
|
},
|
|
140
120
|
|
|
141
121
|
signUp: function(btn) {
|
|
142
|
-
let
|
|
143
|
-
if (!
|
|
144
|
-
|
|
145
|
-
let
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
if (orgIdElement)
|
|
149
|
-
org_id = orgIdElement.value;
|
|
150
|
-
else
|
|
151
|
-
org_id = crud.socket.config.organization_id;
|
|
152
|
-
|
|
153
|
-
let data = {document: {}};
|
|
154
|
-
elements.forEach(el => {
|
|
155
|
-
let name = el.getAttribute('name');
|
|
156
|
-
let value = el.getValue();
|
|
157
|
-
if (!name || !value) return;
|
|
158
|
-
data.document[name] = value;
|
|
159
|
-
});
|
|
122
|
+
let formEl = btn.closest("form");
|
|
123
|
+
if (!formEl) return;
|
|
124
|
+
|
|
125
|
+
let organization_id = crud.socket.config.organization_id;
|
|
126
|
+
let data = form.getData(formEl, 'users')
|
|
160
127
|
data['collection'] = 'users'
|
|
161
|
-
data.document['current_org'] =
|
|
162
|
-
data.document['connected_orgs'] = [
|
|
128
|
+
data.document['current_org'] = organization_id;
|
|
129
|
+
data.document['connected_orgs'] = [organization_id];
|
|
130
|
+
data.organization_id = [organization_id];
|
|
163
131
|
|
|
164
132
|
// const socket = crud.socket.getSockets()
|
|
165
133
|
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
134
|
+
// ToDo: can use updateDocument with filter query
|
|
135
|
+
crud.createDocument(data).then((response) => {
|
|
136
|
+
form.setDocumentId(formEl, response)
|
|
137
|
+
|
|
138
|
+
render.data({
|
|
139
|
+
selector: "[template='signUp']",
|
|
140
|
+
data: {
|
|
141
|
+
type: 'signUp',
|
|
142
|
+
message: 'Succesfully Signed Up',
|
|
143
|
+
success: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
document.dispatchEvent(new CustomEvent('signUp', {
|
|
148
|
+
detail: response
|
|
149
|
+
}));
|
|
181
150
|
|
|
182
|
-
|
|
183
|
-
detail: response
|
|
184
|
-
}));
|
|
185
|
-
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
// } else {
|
|
189
|
-
// // ToDo: creates user in platformdb
|
|
190
|
-
// crud.socket.send('signUp', {
|
|
191
|
-
// collection: 'users',
|
|
192
|
-
// ...data,
|
|
193
|
-
// orgDB: org_id,
|
|
194
|
-
// broadcastBrowser: false
|
|
195
|
-
// });
|
|
196
|
-
// }
|
|
151
|
+
})
|
|
197
152
|
},
|
|
198
153
|
|
|
199
154
|
updateUserStatus: function(data) {
|
|
@@ -275,7 +230,7 @@ const CoCreateUser = {
|
|
|
275
230
|
_id: user_id
|
|
276
231
|
},
|
|
277
232
|
}).then((data) => {
|
|
278
|
-
localStorage.setItem('
|
|
233
|
+
localStorage.setItem('key', data['key']);
|
|
279
234
|
localStorage.setItem('organization_id', data.document[0]['current_org']);
|
|
280
235
|
localStorage.setItem('host', crud.socket.config.host);
|
|
281
236
|
|
|
@@ -287,23 +242,7 @@ const CoCreateUser = {
|
|
|
287
242
|
});
|
|
288
243
|
}
|
|
289
244
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// ToDo: variations of setDocumentId exists in a few components
|
|
293
|
-
setDocumentId: function(collection, id) {
|
|
294
|
-
let orgIdElements = document.querySelectorAll(`[collection='${collection}']`);
|
|
295
|
-
if (orgIdElements && orgIdElements.length > 0) {
|
|
296
|
-
orgIdElements.forEach((el) => {
|
|
297
|
-
if (!el.getAttribute('document_id')) {
|
|
298
|
-
el.setAttribute('document_id', id);
|
|
299
|
-
}
|
|
300
|
-
if (el.getAttribute('name') == "_id") {
|
|
301
|
-
el.value = id;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
245
|
+
}
|
|
307
246
|
};
|
|
308
247
|
|
|
309
248
|
|