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