@cocreate/users 1.40.2 → 1.40.3
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/package.json +1 -2
- package/src/client.js +496 -498
- package/src/server.js +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/users",
|
|
3
|
-
"version": "1.40.
|
|
3
|
+
"version": "1.40.3",
|
|
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",
|
|
@@ -72,7 +72,6 @@
|
|
|
72
72
|
"@cocreate/render@1.46.1": true,
|
|
73
73
|
"@cocreate/socket-client@1.40.5": true,
|
|
74
74
|
"@cocreate/utils@1.42.2": true,
|
|
75
|
-
"@cocreate/uuid@1.12.4": true,
|
|
76
75
|
"@cocreate/webpack@1.4.3": true
|
|
77
76
|
}
|
|
78
77
|
}
|
package/src/client.js
CHANGED
|
@@ -5,518 +5,516 @@ import Elements from "@cocreate/elements";
|
|
|
5
5
|
import { render } from "@cocreate/render";
|
|
6
6
|
import "@cocreate/element-prototype";
|
|
7
7
|
import Observer from "@cocreate/observer";
|
|
8
|
-
import "./index.css";
|
|
9
|
-
|
|
10
|
-
// TODO: Replace with @cocreate/config.
|
|
11
|
-
import localStorage from "@cocreate/local-storage";
|
|
12
8
|
import Config from "@cocreate/config";
|
|
9
|
+
import "./index.css";
|
|
13
10
|
|
|
14
11
|
const CoCreateUser = {
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
12
|
+
organization_id: async () => {
|
|
13
|
+
return await Crud.socket.organization_id();
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
init: function () {
|
|
17
|
+
this.initSocket();
|
|
18
|
+
this.initSession();
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
initSocket: function () {
|
|
22
|
+
const self = this;
|
|
23
|
+
Crud.listen("updateUserStatus", (data) => self.updateUserStatus(data));
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
signUp: async function (action) {
|
|
27
|
+
if (!action.form) return;
|
|
28
|
+
|
|
29
|
+
let data = await Elements.getData(action.form);
|
|
30
|
+
let user = data[0];
|
|
31
|
+
|
|
32
|
+
let userKey = {
|
|
33
|
+
method: "object.create",
|
|
34
|
+
array: "keys",
|
|
35
|
+
object: {
|
|
36
|
+
type: "user",
|
|
37
|
+
key: user.object._id || user.object[0]?._id,
|
|
38
|
+
roles: user.object.roles || [user.object["roles[]"]] || user.object[0]?.roles,
|
|
39
|
+
email: user.object.email || user.object[0]?.email,
|
|
40
|
+
password: user.object.password || window.btoa("0000"),
|
|
41
|
+
array: user.array
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const socket = await Crud.socket.getSockets();
|
|
46
|
+
if (
|
|
47
|
+
!socket[0] ||
|
|
48
|
+
!socket[0].connected ||
|
|
49
|
+
(window && !window.navigator.onLine) ||
|
|
50
|
+
Crud.socket.serverOrganization == false
|
|
51
|
+
) {
|
|
52
|
+
user.method = "object.create";
|
|
53
|
+
await Crud.send(user);
|
|
54
|
+
let response = await Crud.send(userKey);
|
|
55
|
+
if (response && response.object && response.object[0]) {
|
|
56
|
+
this.signUpResponse(response, action);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
let request = {
|
|
60
|
+
method: "signUp",
|
|
61
|
+
user,
|
|
62
|
+
userKey,
|
|
63
|
+
broadcastBrowser: false
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Crud.socket.send(request).then((response) => {
|
|
67
|
+
this.signUpResponse(response, action);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
signUpResponse: function (response, action) {
|
|
73
|
+
render({
|
|
74
|
+
selector: "[template*='signUp']",
|
|
75
|
+
data: [
|
|
76
|
+
{
|
|
77
|
+
type: "signUp",
|
|
78
|
+
message: "Succesfully Signed Up",
|
|
79
|
+
success: true
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
action.element.dispatchEvent(
|
|
85
|
+
new CustomEvent("signUp", {
|
|
86
|
+
detail: response
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
signIn: async function (action) {
|
|
92
|
+
if (!action.form) return;
|
|
93
|
+
let query = {};
|
|
94
|
+
|
|
95
|
+
const inputs = action.form.querySelectorAll(
|
|
96
|
+
'input[key="email"], input[key="password"], input[key="username"]'
|
|
97
|
+
);
|
|
98
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
99
|
+
const key = inputs[i].getAttribute("key");
|
|
100
|
+
if (key === "password" && inputs[i].type === "text") {
|
|
101
|
+
inputs[i].type = "password"
|
|
102
|
+
}
|
|
103
|
+
const value = await inputs[i].getValue();
|
|
104
|
+
query[key] = value;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let request = {
|
|
108
|
+
method: "object.read",
|
|
109
|
+
array: "keys",
|
|
110
|
+
$filter: {
|
|
111
|
+
query
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const socket = await Crud.socket.getSockets();
|
|
116
|
+
if (
|
|
117
|
+
!socket[0] ||
|
|
118
|
+
!socket[0].connected ||
|
|
119
|
+
(window && !window.navigator.onLine) ||
|
|
120
|
+
Crud.socket.serverOrganization == false
|
|
121
|
+
) {
|
|
122
|
+
Crud.send(request).then((response) => {
|
|
123
|
+
response["success"] = false;
|
|
124
|
+
response["status"] = "signIn failed";
|
|
125
|
+
response["message"] = "offline";
|
|
126
|
+
if (response.object && response.object[0]) {
|
|
127
|
+
response["success"] = true;
|
|
128
|
+
response["status"] = "success";
|
|
129
|
+
response["user_id"] = response.object[0].key;
|
|
130
|
+
}
|
|
131
|
+
this.signInResponse(response, action);
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
request.method = "signIn";
|
|
135
|
+
request.broadcastBrowser = false;
|
|
136
|
+
delete request.storage;
|
|
137
|
+
Crud.socket.send(request).then((response) => {
|
|
138
|
+
this.signInResponse(response, action);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
signInResponse: function (data, action) {
|
|
144
|
+
let { success, status, message, organization_id, user_id, token } =
|
|
145
|
+
data;
|
|
146
|
+
if (success) {
|
|
147
|
+
// Updated to synchronize values isomorphic-safely via our configuration manager API
|
|
148
|
+
Config.set("organization_id", organization_id);
|
|
149
|
+
Config.set("key", Crud.socket.key);
|
|
150
|
+
Config.set("host", Crud.socket.host);
|
|
151
|
+
Config.set("user_id", user_id);
|
|
152
|
+
Config.set("token", token);
|
|
153
|
+
message = "Successful signIn";
|
|
154
|
+
Crud.socket.user_id = user_id;
|
|
155
|
+
} else if (!message) {
|
|
156
|
+
message = "The email or password you entered is incorrect";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
render({
|
|
160
|
+
selector: "[template*='signIn']",
|
|
161
|
+
data: [
|
|
162
|
+
{
|
|
163
|
+
type: "signIn",
|
|
164
|
+
status,
|
|
165
|
+
message,
|
|
166
|
+
success
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
action.element.dispatchEvent(
|
|
172
|
+
new CustomEvent("signIn", {
|
|
173
|
+
detail: {}
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
signOut: function (action) {
|
|
179
|
+
// Synchronously evict user configuration metadata
|
|
180
|
+
Config.remove("user_id");
|
|
181
|
+
Config.remove("token");
|
|
182
|
+
|
|
183
|
+
if (Crud && Crud.socket) {
|
|
184
|
+
Crud.socket.user_id = null;
|
|
185
|
+
if (Crud.socket.token) Crud.socket.token = null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
render({
|
|
189
|
+
selector: "[template*='signOut']",
|
|
190
|
+
data: [
|
|
191
|
+
{
|
|
192
|
+
type: "signOut",
|
|
193
|
+
message: "Succesfully logged out",
|
|
194
|
+
success: true
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
action.element.dispatchEvent(new CustomEvent("signOut"));
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
updateUserStatus: function (data) {
|
|
203
|
+
this.redirect(data);
|
|
204
|
+
let statusEls;
|
|
205
|
+
if (data.user_id) {
|
|
206
|
+
if (data.user_id === Crud.socket.user_id)
|
|
207
|
+
statusEls = document.querySelectorAll(
|
|
208
|
+
`[user-status][object='${data["user_id"]}'], [user-status][object='$user_id']`
|
|
209
|
+
);
|
|
210
|
+
else
|
|
211
|
+
statusEls = document.querySelectorAll(
|
|
212
|
+
`[user-status][object='${data["user_id"]}']`
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
statusEls.forEach((el) => {
|
|
216
|
+
el.setAttribute("user-status", data["userStatus"]);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
redirect: (data) => {
|
|
222
|
+
const userStatus = data.userStatus;
|
|
223
|
+
|
|
224
|
+
if (
|
|
225
|
+
(data.user_id && data.user_id !== Crud.socket.user_id) ||
|
|
226
|
+
(data.clientId && data.clientId !== Crud.socket.clientId)
|
|
227
|
+
)
|
|
228
|
+
return;
|
|
229
|
+
|
|
230
|
+
let redirectTag;
|
|
231
|
+
if (userStatus == "online" || userStatus == "idle") {
|
|
232
|
+
redirectTag = document.querySelector('[session="true"]');
|
|
233
|
+
} else if (userStatus == "offline") {
|
|
234
|
+
redirectTag = document.querySelector('[session="false"]');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (redirectTag) {
|
|
238
|
+
let redirectLink = redirectTag.getAttribute("href");
|
|
239
|
+
if (redirectLink) {
|
|
240
|
+
if (userStatus == "offline") {
|
|
241
|
+
// Corrected bug: Changed legacy or non-existent .removeItem() to standard .remove()
|
|
242
|
+
Config.remove("user_id");
|
|
243
|
+
Config.remove("token");
|
|
244
|
+
if (Crud && Crud.socket) Crud.socket.user_id = null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Normalize both URLs to compare paths in a uniform way
|
|
248
|
+
const currentPath = new URL(location.href).pathname.replace(
|
|
249
|
+
"/index.html",
|
|
250
|
+
"/"
|
|
251
|
+
);
|
|
252
|
+
const targetPath = new URL(
|
|
253
|
+
redirectLink,
|
|
254
|
+
location.href
|
|
255
|
+
).pathname.replace("/index.html", "/");
|
|
256
|
+
|
|
257
|
+
if (currentPath !== targetPath) {
|
|
258
|
+
location.href = redirectLink;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (userStatus) {
|
|
264
|
+
let sessionElements = document.querySelectorAll(
|
|
265
|
+
'[session]:not([session="true"], [session="false"])'
|
|
266
|
+
);
|
|
267
|
+
for (let i = 0; i < sessionElements.length; i++)
|
|
268
|
+
sessionElements[i].setAttribute("session", userStatus);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
initSession: () => {
|
|
273
|
+
let redirectTag = document.querySelector("[session]");
|
|
274
|
+
|
|
275
|
+
if (redirectTag) {
|
|
276
|
+
Crud.socket.send({
|
|
277
|
+
method: "checkSession",
|
|
278
|
+
broadcast: false,
|
|
279
|
+
broadcastSender: false,
|
|
280
|
+
broadcastBrowser: false
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
inviteUser: async function (action) {
|
|
286
|
+
let email = action.form.querySelector('input[key="email"]');
|
|
287
|
+
if (!email) return;
|
|
288
|
+
else email = await email.getValue();
|
|
289
|
+
|
|
290
|
+
let name = action.form.querySelector('input[key="name"]');
|
|
291
|
+
if (name) name = await name.getValue();
|
|
292
|
+
|
|
293
|
+
let from = action.form.querySelector('input[key="from"]');
|
|
294
|
+
if (from) from = await from.getValue();
|
|
295
|
+
|
|
296
|
+
let origin = action.form.querySelector('input[key="origin"]');
|
|
297
|
+
if (origin)
|
|
298
|
+
origin = (await origin.getValue()) || window.location.origin;
|
|
299
|
+
|
|
300
|
+
let hostname = action.form.querySelector('input[key="hostname"]');
|
|
301
|
+
if (hostname)
|
|
302
|
+
hostname = (await hostname.getValue()) || window.location.hostname;
|
|
303
|
+
|
|
304
|
+
let path = action.form.querySelector('input[key="path"]');
|
|
305
|
+
if (path) path = await path.getValue();
|
|
306
|
+
|
|
307
|
+
let request = {
|
|
308
|
+
method: "inviteUser",
|
|
309
|
+
name,
|
|
310
|
+
email,
|
|
311
|
+
from,
|
|
312
|
+
origin,
|
|
313
|
+
hostname,
|
|
314
|
+
path
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
Crud.socket.send(request).then((response) => {
|
|
318
|
+
if (response.success)
|
|
319
|
+
action.element.dispatchEvent(new CustomEvent("inviteUser"));
|
|
320
|
+
|
|
321
|
+
render({
|
|
322
|
+
selector: "[template*='inviteUser']",
|
|
323
|
+
data: [
|
|
324
|
+
{
|
|
325
|
+
type: "inviteUser",
|
|
326
|
+
message: response.message,
|
|
327
|
+
success: response.success
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
acceptInvite: async function (action) {
|
|
335
|
+
let data = {
|
|
336
|
+
method: "acceptInvite",
|
|
337
|
+
success: false
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
let token = action.form.querySelector('input[key="token"]');
|
|
341
|
+
if (token) data.token = await token.getValue();
|
|
342
|
+
let user_id = action.form.querySelector('input[key="_id"]');
|
|
343
|
+
if (user_id) data.user_id = await user_id.getValue();
|
|
344
|
+
let email = action.form.querySelector('input[key="email"]');
|
|
345
|
+
if (email) data.email = await email.getValue();
|
|
346
|
+
|
|
347
|
+
if (data.token && data.user_id) {
|
|
348
|
+
data = await Crud.socket.send(data);
|
|
349
|
+
} else {
|
|
350
|
+
data.message = "Invitation failed";
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (data.success)
|
|
354
|
+
action.element.dispatchEvent(new CustomEvent("acceptInvite"));
|
|
355
|
+
render({
|
|
356
|
+
selector: "[template*='acceptInvite']",
|
|
357
|
+
data: [
|
|
358
|
+
{
|
|
359
|
+
type: "acceptInvite",
|
|
360
|
+
message: data.message,
|
|
361
|
+
success: data.success
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
forgotPassword: async function (action) {
|
|
368
|
+
let email = action.form.querySelector('input[key="email"]');
|
|
369
|
+
if (!email) return;
|
|
370
|
+
else email = await email.getValue();
|
|
371
|
+
|
|
372
|
+
let from = action.form.querySelector('input[key="from"]');
|
|
373
|
+
if (from) from = await from.getValue();
|
|
374
|
+
|
|
375
|
+
let origin = action.form.querySelector('input[key="origin"]');
|
|
376
|
+
if (origin)
|
|
377
|
+
origin = (await origin.getValue()) || window.location.origin;
|
|
378
|
+
|
|
379
|
+
let hostname = action.form.querySelector('input[key="hostname"]');
|
|
380
|
+
if (hostname)
|
|
381
|
+
hostname = (await hostname.getValue()) || window.location.hostname;
|
|
382
|
+
|
|
383
|
+
let path = action.form.querySelector('input[key="path"]');
|
|
384
|
+
if (path) path = await path.getValue();
|
|
385
|
+
|
|
386
|
+
let request = {
|
|
387
|
+
method: "forgotPassword",
|
|
388
|
+
email,
|
|
389
|
+
from,
|
|
390
|
+
origin,
|
|
391
|
+
hostname,
|
|
392
|
+
path
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
Crud.socket.send(request).then((response) => {
|
|
396
|
+
if (response.success)
|
|
397
|
+
action.element.dispatchEvent(new CustomEvent("forgotPassword"));
|
|
398
|
+
render({
|
|
399
|
+
selector: "[template*='forgotPassword']",
|
|
400
|
+
data: [
|
|
401
|
+
{
|
|
402
|
+
type: "forgotPassword",
|
|
403
|
+
message: response.message,
|
|
404
|
+
success: response.success
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
resetPassword: async function (action) {
|
|
412
|
+
let data = {
|
|
413
|
+
method: "resetPassword"
|
|
414
|
+
};
|
|
415
|
+
let email = action.form.querySelector('input[key="email"]');
|
|
416
|
+
if (email) data.email = await email.getValue();
|
|
417
|
+
else return;
|
|
418
|
+
|
|
419
|
+
let password = action.form.querySelector('input[key="password"]');
|
|
420
|
+
if (password) data.password = await password.getValue();
|
|
421
|
+
else return;
|
|
422
|
+
|
|
423
|
+
let token = action.form.querySelector('input[key="token"]');
|
|
424
|
+
if (token) data.token = await token.getValue();
|
|
425
|
+
else return;
|
|
426
|
+
|
|
427
|
+
Crud.socket.send(data).then((data) => {
|
|
428
|
+
if (data.success)
|
|
429
|
+
action.element.dispatchEvent(new CustomEvent("resetPassword"));
|
|
430
|
+
else
|
|
431
|
+
render({
|
|
432
|
+
selector: "[template*='resetPassword']",
|
|
433
|
+
data: [
|
|
434
|
+
{
|
|
435
|
+
type: "resetPassword",
|
|
436
|
+
message: data.message,
|
|
437
|
+
success: data.success
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
}
|
|
445
443
|
};
|
|
446
444
|
|
|
447
445
|
Actions.init([
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
446
|
+
{
|
|
447
|
+
name: "signUp",
|
|
448
|
+
endEvent: "signUp",
|
|
449
|
+
callback: (action) => {
|
|
450
|
+
CoCreateUser.signUp(action);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: "signIn",
|
|
455
|
+
endEvent: "signIn",
|
|
456
|
+
callback: (action) => {
|
|
457
|
+
CoCreateUser.signIn(action);
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: "signOut",
|
|
462
|
+
endEvent: "signOut",
|
|
463
|
+
callback: (action) => {
|
|
464
|
+
CoCreateUser.signOut(action);
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "inviteUser",
|
|
469
|
+
endEvent: "inviteUser",
|
|
470
|
+
callback: (action) => {
|
|
471
|
+
CoCreateUser.inviteUser(action);
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
name: "acceptInvite",
|
|
476
|
+
endEvent: "acceptInvite",
|
|
477
|
+
callback: (action) => {
|
|
478
|
+
CoCreateUser.acceptInvite(action);
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: "forgotPassword",
|
|
483
|
+
endEvent: "forgotPassword",
|
|
484
|
+
callback: (action) => {
|
|
485
|
+
CoCreateUser.forgotPassword(action);
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "resetPassword",
|
|
490
|
+
endEvent: "resetPassword",
|
|
491
|
+
callback: (action) => {
|
|
492
|
+
CoCreateUser.resetPassword(action);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
497
495
|
]);
|
|
498
496
|
|
|
499
497
|
let checkSessionTimeout;
|
|
500
498
|
function checkSession() {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
499
|
+
clearTimeout(checkSessionTimeout);
|
|
500
|
+
checkSessionTimeout = setTimeout(function () {
|
|
501
|
+
Crud.socket.send({
|
|
502
|
+
method: "checkSession",
|
|
503
|
+
broadcast: false,
|
|
504
|
+
broadcastBrowser: false
|
|
505
|
+
});
|
|
506
|
+
}, 500);
|
|
509
507
|
}
|
|
510
508
|
|
|
511
509
|
Observer.init({
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
510
|
+
name: "CoCreateUserSessionAddedNodes",
|
|
511
|
+
types: ["addedNodes"],
|
|
512
|
+
selector: "[session]",
|
|
513
|
+
callback: () => {
|
|
514
|
+
checkSession();
|
|
515
|
+
}
|
|
518
516
|
});
|
|
519
517
|
|
|
520
518
|
CoCreateUser.init();
|
|
521
519
|
|
|
522
|
-
export default CoCreateUser;
|
|
520
|
+
export default CoCreateUser;
|
package/src/server.js
CHANGED
|
@@ -36,7 +36,7 @@ async function signUp(data) {
|
|
|
36
36
|
success: false,
|
|
37
37
|
message: "signUp failed",
|
|
38
38
|
organization_id: data.organization_id,
|
|
39
|
-
|
|
39
|
+
uuid: data.uuid
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const targetEmail = data.user?.object?.email;
|
|
@@ -152,7 +152,7 @@ async function signIn(data) {
|
|
|
152
152
|
message: "signIn failed",
|
|
153
153
|
userStatus: "offline",
|
|
154
154
|
organization_id: result.organization_id,
|
|
155
|
-
|
|
155
|
+
uuid: result.uuid
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
if (
|
|
@@ -285,8 +285,8 @@ async function inviteUser(data) {
|
|
|
285
285
|
if (!server || !server.crud) return;
|
|
286
286
|
|
|
287
287
|
const inviteId = server.crud.ObjectId().toString();
|
|
288
|
-
let
|
|
289
|
-
delete data.
|
|
288
|
+
let uuid = data.uuid;
|
|
289
|
+
delete data.uuid;
|
|
290
290
|
|
|
291
291
|
let targetArray = "users"; // default fallback
|
|
292
292
|
let keyData = await server.crud.send({
|
|
@@ -385,7 +385,7 @@ async function inviteUser(data) {
|
|
|
385
385
|
success: true,
|
|
386
386
|
message: "Successfully sent invite",
|
|
387
387
|
organization_id: updatedData.organization_id,
|
|
388
|
-
|
|
388
|
+
uuid
|
|
389
389
|
};
|
|
390
390
|
|
|
391
391
|
if (server.wsManager) {
|
|
@@ -410,8 +410,8 @@ async function acceptInvite(data) {
|
|
|
410
410
|
return;
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
let
|
|
414
|
-
delete data.
|
|
413
|
+
let uuid = data.uuid;
|
|
414
|
+
delete data.uuid;
|
|
415
415
|
|
|
416
416
|
data.method = "object.update";
|
|
417
417
|
data.array = "users";
|
|
@@ -439,7 +439,7 @@ async function acceptInvite(data) {
|
|
|
439
439
|
message:
|
|
440
440
|
"The token is invalid or has expired. However, you can still access your account. Please request a new invite to proceed, and feel free to explore the available features while you wait.",
|
|
441
441
|
organization_id: updatedData.organization_id,
|
|
442
|
-
|
|
442
|
+
uuid
|
|
443
443
|
};
|
|
444
444
|
|
|
445
445
|
for (let object of updatedData.object) {
|
|
@@ -502,7 +502,7 @@ async function forgotPassword(data) {
|
|
|
502
502
|
success: false,
|
|
503
503
|
message: "Email does not exist",
|
|
504
504
|
organization_id: result.organization_id,
|
|
505
|
-
|
|
505
|
+
uuid: result.uuid
|
|
506
506
|
};
|
|
507
507
|
|
|
508
508
|
for (let object of result.object) {
|
|
@@ -588,7 +588,7 @@ async function resetPassword(data) {
|
|
|
588
588
|
success: false,
|
|
589
589
|
message: "Token is invalid or has expired",
|
|
590
590
|
organization_id: result.organization_id,
|
|
591
|
-
|
|
591
|
+
uuid: result.uuid
|
|
592
592
|
};
|
|
593
593
|
|
|
594
594
|
for (let object of result.object) {
|