@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/src/client.js CHANGED
@@ -1,482 +1,498 @@
1
1
  /*globals CustomEvent, btoa*/
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';
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 '@cocreate/local-storage';
11
+ import localStorage from "@cocreate/local-storage";
12
12
 
13
13
  const CoCreateUser = {
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
- 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
-
83
- signIn: async function (action) {
84
- if (!action.form) return;
85
- let query = {};
86
-
87
- const inputs = action.form.querySelectorAll('input[key="email"], input[key="password"], input[key="username"]');
88
- for (let i = 0; i < inputs.length; i++) {
89
- const key = inputs[i].getAttribute('key');
90
- const value = await inputs[i].getValue();
91
- query[key] = value
92
- }
93
-
94
- let request = {
95
- method: 'object.read',
96
- array: 'keys',
97
- $filter: {
98
- query
99
- }
100
- }
101
-
102
- const socket = await Crud.socket.getSockets()
103
- if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || Crud.socket.serverOrganization == false) {
104
- Crud.send(request).then((response) => {
105
- response['success'] = false
106
- response['status'] = "signIn failed"
107
- if (response.object && response.object[0]) {
108
- response['success'] = true
109
- response['status'] = "success"
110
- response['user_id'] = response.object[0].key
111
- }
112
- this.signInResponse(response)
113
- })
114
- } else {
115
- request.method = 'signIn'
116
- request.broadcastBrowser = false
117
- delete request.storage
118
- Crud.socket.send(request).then((response) => {
119
- this.signInResponse(response)
120
- })
121
- }
122
- },
123
-
124
- signInResponse: function (data) {
125
- let { success, status, message, organization_id, user_id, token } = data;
126
- if (success) {
127
- localStorage.setItem('organization_id', organization_id);
128
- localStorage.setItem("key", Crud.socket.key);
129
- localStorage.setItem("host", Crud.socket.host);
130
- localStorage.setItem('user_id', user_id);
131
- localStorage.setItem("token", token);
132
- message = "Successful signIn";
133
- Crud.socket.user_id = user_id
134
-
135
- document.dispatchEvent(new CustomEvent('signIn', {
136
- detail: {}
137
- }));
138
- }
139
- else
140
- message = "The email or password you entered is incorrect";
141
-
142
- render({
143
- selector: "[template*='signIn']",
144
- data: [{
145
- type: 'signIn',
146
- status,
147
- message,
148
- success
149
- }]
150
- });
151
- },
152
-
153
- signOut: () => {
154
- self = this;
155
- localStorage.removeItem("user_id");
156
- localStorage.removeItem("token");
157
-
158
- render({
159
- selector: "[template*='signOut']",
160
- data: [{
161
- type: 'signOut',
162
- message: 'Succesfully logged out',
163
- success: true
164
- }]
165
- });
166
-
167
- // TODO: replace with Custom event system
168
- document.dispatchEvent(new CustomEvent('signOut'));
169
- },
170
-
171
- updateUserStatus: function (data) {
172
- this.redirect(data)
173
- let statusEls
174
- if (data.user_id) {
175
- if (data.user_id === Crud.socket.user_id)
176
- statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}'], [user-status][object='$user_id']`);
177
- else
178
- statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}']`);
179
-
180
- statusEls.forEach((el) => {
181
- el.setAttribute('user-status', data['userStatus']);
182
- });
183
- }
184
-
185
- },
186
-
187
- redirect: (data) => {
188
- if (data.user_id && data.user_id !== Crud.socket.user_id || data.clientId && data.clientId !== Crud.socket.clientId)
189
- return
190
-
191
- let redirectTag
192
- if (data.userStatus == 'on' || data.userStatus == 'idle') {
193
- redirectTag = document.querySelector('[session="true"]');
194
- } else if (data.userStatus == 'off') {
195
- redirectTag = document.querySelector('[session="false"]');
196
- }
197
-
198
- if (redirectTag) {
199
- let redirectLink = redirectTag.getAttribute('href');
200
- if (redirectLink) {
201
- if (data.userStatus == 'off') {
202
- localStorage.removeItem("user_id");
203
- localStorage.removeItem("token");
204
- }
205
-
206
- // Normalize both URLs to compare paths in a uniform way
207
- const currentPath = new URL(location.href).pathname.replace('/index.html', '/');
208
- const targetPath = new URL(redirectLink, location.href).pathname.replace('/index.html', '/');
209
-
210
- if (currentPath !== targetPath) {
211
- location.href = redirectLink;
212
- }
213
-
214
- }
215
-
216
- }
217
-
218
- if (data.userStatus) {
219
- let sessionElements = document.querySelectorAll('[session]:not([session="true"], [session="false"])');
220
- for (let i = 0; i < sessionElements.length; i++)
221
- sessionElements[i].setAttribute('session', data.userStatus)
222
- }
223
- },
224
-
225
- initSession: () => {
226
- let redirectTag = document.querySelector('[session]');
227
-
228
- if (redirectTag) {
229
- Crud.socket.send({
230
- method: 'checkSession',
231
- broadcast: false,
232
- broadcastSender: false,
233
- broadcastBrowser: false
234
- });
235
- }
236
-
237
- },
238
-
239
- inviteUser: async function (action) {
240
- let email = action.form.querySelector('input[key="email"]');
241
- if (!email)
242
- return
243
- else
244
- email = await email.getValue()
245
-
246
- let name = action.form.querySelector('input[key="name"]');
247
- if (name)
248
- name = await name.getValue()
249
-
250
- let from = action.form.querySelector('input[key="from"]');
251
- if (from)
252
- from = await from.getValue()
253
-
254
- let origin = action.form.querySelector('input[key="origin"]');
255
- if (origin)
256
- origin = await origin.getValue() || window.location.origin
257
-
258
- let hostname = action.form.querySelector('input[key="hostname"]');
259
- if (hostname)
260
- hostname = await hostname.getValue() || window.location.hostname
261
-
262
- let path = action.form.querySelector('input[key="path"]');
263
- if (path)
264
- path = await path.getValue()
265
-
266
- let request = {
267
- method: 'inviteUser',
268
- name,
269
- email,
270
- from,
271
- origin,
272
- hostname,
273
- path
274
- }
275
-
276
- Crud.socket.send(request).then((response) => {
277
- if (response.success)
278
- document.dispatchEvent(new CustomEvent('inviteUser'));
279
-
280
- render({
281
- selector: "[template*='inviteUser']",
282
- data: [{
283
- type: 'inviteUser',
284
- message: response.message,
285
- success: response.success
286
- }]
287
- });
288
-
289
- })
290
- },
291
-
292
- acceptInvite: async function (action) {
293
- let data = {
294
- method: 'acceptInvite',
295
- success: false
296
- }
297
-
298
- let token = action.form.querySelector('input[key="token"]');
299
- if (token)
300
- data.token = await token.getValue()
301
- let user_id = action.form.querySelector('input[key="_id"]');
302
- if (user_id)
303
- data.user_id = await user_id.getValue()
304
- let email = action.form.querySelector('input[key="email"]');
305
- if (email)
306
- data.email = await email.getValue()
307
-
308
- if (data.token && data.user_id) {
309
- data = await Crud.socket.send(data)
310
- } else {
311
- data.message = 'Invitation failed'
312
- }
313
-
314
- if (data.success)
315
- document.dispatchEvent(new CustomEvent('acceptInvite'));
316
- render({
317
- selector: "[template*='acceptInvite']",
318
- data: [{
319
- type: 'acceptInvite',
320
- message: data.message,
321
- success: data.success,
322
- }]
323
- });
324
- },
325
-
326
-
327
- forgotPassword: async function (action) {
328
- let email = action.form.querySelector('input[key="email"]');
329
- if (!email)
330
- return
331
- else
332
- email = await email.getValue()
333
-
334
- let from = action.form.querySelector('input[key="from"]');
335
- if (from)
336
- from = await from.getValue()
337
-
338
- let origin = action.form.querySelector('input[key="origin"]');
339
- if (origin)
340
- origin = await origin.getValue() || window.location.origin
341
-
342
- let hostname = action.form.querySelector('input[key="hostname"]');
343
- if (hostname)
344
- hostname = await hostname.getValue() || window.location.hostname
345
-
346
- let path = action.form.querySelector('input[key="path"]');
347
- if (path)
348
- path = await path.getValue()
349
-
350
- let request = {
351
- method: 'forgotPassword',
352
- email,
353
- from,
354
- origin,
355
- hostname,
356
- path
357
- }
358
-
359
- Crud.socket.send(request).then((response) => {
360
- if (response.success)
361
- document.dispatchEvent(new CustomEvent('forgotPassword'));
362
- render({
363
- selector: "[template*='forgotPassword']",
364
- data: [{
365
- type: 'forgotPassword',
366
- message: response.message,
367
- success: response.success
368
- }]
369
- });
370
-
371
- })
372
- },
373
-
374
- resetPassword: async function (action) {
375
- let data = {
376
- method: 'resetPassword'
377
- }
378
- let email = action.form.querySelector('input[key="email"]');
379
- if (email)
380
- data.email = await email.getValue()
381
- else return
382
-
383
- let password = action.form.querySelector('input[key="password"]');
384
- if (password)
385
- data.password = await password.getValue()
386
- else return
387
-
388
- let token = action.form.querySelector('input[key="token"]');
389
- if (token)
390
- data.token = await token.getValue()
391
- else return
392
-
393
- Crud.socket.send(data).then((data) => {
394
- if (data.success)
395
- document.dispatchEvent(new CustomEvent('resetPassword'));
396
- else
397
- render({
398
- selector: "[template*='resetPassword']",
399
- data: [{
400
- type: 'resetPassword',
401
- message: data.message,
402
- success: data.success,
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
- name: "signUp",
412
- endEvent: "signUp",
413
- callback: (action) => {
414
- CoCreateUser.signUp(action);
415
- }
416
- },
417
- {
418
- name: "signIn",
419
- endEvent: "signIn",
420
- callback: (action) => {
421
- CoCreateUser.signIn(action);
422
- }
423
- },
424
- {
425
- name: "signOut",
426
- endEvent: "signOut",
427
- callback: (action) => {
428
- CoCreateUser.signOut(action);
429
- }
430
- },
431
- {
432
- name: "inviteUser",
433
- endEvent: "inviteUser",
434
- callback: (action) => {
435
- CoCreateUser.inviteUser(action);
436
- }
437
- },
438
- {
439
- name: "acceptInvite",
440
- endEvent: "acceptInvite",
441
- callback: (action) => {
442
- CoCreateUser.acceptInvite(action);
443
- }
444
- },
445
- {
446
- name: "forgotPassword",
447
- endEvent: "forgotPassword",
448
- callback: (action) => {
449
- CoCreateUser.forgotPassword(action);
450
- }
451
- },
452
- {
453
- name: "resetPassword",
454
- endEvent: "resetPassword",
455
- callback: (action) => {
456
- CoCreateUser.resetPassword(action);
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
- clearTimeout(checkSessionTimeout);
464
- checkSessionTimeout = setTimeout(function () {
465
- Crud.socket.send({
466
- method: 'checkSession',
467
- broadcast: false,
468
- broadcastBrowser: false
469
- });
470
- }, 500);
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
- name: 'CoCreateUserSessionAddedNodes',
475
- observe: ['addedNodes'],
476
- selector: '[session]',
477
- callback: () => {
478
- checkSession();
479
- }
490
+ name: "CoCreateUserSessionAddedNodes",
491
+ types: ["addedNodes"],
492
+ selector: "[session]",
493
+ callback: () => {
494
+ checkSession();
495
+ }
480
496
  });
481
497
 
482
498
  CoCreateUser.init();