@cocreate/users 1.2.34 → 1.4.0
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 +28 -0
- package/package.json +7 -7
- package/src/index.js +58 -40
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.3.2...v1.4.0) (2021-10-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* opens socket chaner for user Status ([e875c8d](https://github.com/CoCreate-app/CoCreate-users/commit/e875c8d904df36e9136df9484ddac461ce560bb3))
|
|
7
|
+
|
|
8
|
+
## [1.3.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.3.1...v1.3.2) (2021-10-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* dispatch login endEvent if succesful ([ac4b37d](https://github.com/CoCreate-app/CoCreate-users/commit/ac4b37dc723d90db9cd9aa963fbd166da9331905))
|
|
14
|
+
|
|
15
|
+
## [1.3.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.3.0...v1.3.1) (2021-10-14)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* dispatch login endEvent ([5385212](https://github.com/CoCreate-app/CoCreate-users/commit/5385212be9eb2e31d9c4cbe48424231d111489ad))
|
|
21
|
+
|
|
22
|
+
# [1.3.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.2.34...v1.3.0) (2021-10-14)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* render log for success ([24480a0](https://github.com/CoCreate-app/CoCreate-users/commit/24480a036390608b9ad1cf79dd68c995df1991ac))
|
|
28
|
+
|
|
1
29
|
## [1.2.34](https://github.com/CoCreate-app/CoCreate-users/compare/v1.2.33...v1.2.34) (2021-10-13)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/users",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/action": "^1.2.
|
|
65
|
-
"@cocreate/crud-client": "^1.4.
|
|
66
|
-
"@cocreate/docs": "^1.2.
|
|
67
|
-
"@cocreate/form": "^1.2.
|
|
68
|
-
"@cocreate/input": "^1.2.
|
|
69
|
-
"@cocreate/render": "^1.
|
|
64
|
+
"@cocreate/action": "^1.2.29",
|
|
65
|
+
"@cocreate/crud-client": "^1.4.2",
|
|
66
|
+
"@cocreate/docs": "^1.2.32",
|
|
67
|
+
"@cocreate/form": "^1.2.30",
|
|
68
|
+
"@cocreate/input": "^1.2.35",
|
|
69
|
+
"@cocreate/render": "^1.3.0"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/index.js
CHANGED
|
@@ -13,18 +13,30 @@ const CoCreateUser = {
|
|
|
13
13
|
this.initSocket();
|
|
14
14
|
this.initChangeOrg();
|
|
15
15
|
this.checkSession();
|
|
16
|
+
this.createUserSocket();
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
createUserSocket: function() {
|
|
20
|
+
var user_id = window.localStorage.getItem('user_id');
|
|
21
|
+
if (user_id) {
|
|
22
|
+
crud.socket.create({
|
|
23
|
+
namespace: 'users',
|
|
24
|
+
room: user_id,
|
|
25
|
+
host: window.config.host
|
|
26
|
+
})
|
|
27
|
+
}
|
|
16
28
|
},
|
|
17
29
|
|
|
18
30
|
initSocket: function() {
|
|
19
31
|
const self = this;
|
|
20
32
|
crud.listen('createUser', function(data) {
|
|
21
33
|
self.setDocumentId('users', data.document_id);
|
|
22
|
-
document.dispatchEvent(new CustomEvent('
|
|
34
|
+
document.dispatchEvent(new CustomEvent('createUser', {
|
|
23
35
|
detail: data
|
|
24
36
|
}));
|
|
25
37
|
});
|
|
26
38
|
crud.listen('createUserNew', function(data) {
|
|
27
|
-
document.dispatchEvent(new CustomEvent('
|
|
39
|
+
document.dispatchEvent(new CustomEvent('createUserNew', {
|
|
28
40
|
detail: data
|
|
29
41
|
}));
|
|
30
42
|
});
|
|
@@ -45,12 +57,12 @@ const CoCreateUser = {
|
|
|
45
57
|
inputs.forEach((input) => {
|
|
46
58
|
const name = input.getAttribute('name');
|
|
47
59
|
let value = input.value;
|
|
48
|
-
if(input.type == 'password') {
|
|
60
|
+
if (input.type == 'password') {
|
|
49
61
|
value = btoa(value);
|
|
50
62
|
}
|
|
51
63
|
collection = input.getAttribute('collection') || collection;
|
|
52
64
|
|
|
53
|
-
if(name) {
|
|
65
|
+
if (name) {
|
|
54
66
|
loginData[name] = value;
|
|
55
67
|
}
|
|
56
68
|
});
|
|
@@ -64,24 +76,30 @@ const CoCreateUser = {
|
|
|
64
76
|
},
|
|
65
77
|
|
|
66
78
|
loginResult: function(data) {
|
|
67
|
-
|
|
79
|
+
let { success, status, message, token } = data;
|
|
68
80
|
|
|
69
|
-
if(success) {
|
|
81
|
+
if (success) {
|
|
70
82
|
window.localStorage.setItem('user_id', data['id']);
|
|
71
83
|
window.localStorage.setItem("token", token);
|
|
72
84
|
document.cookie = `token=${token};path=/`;
|
|
73
85
|
this.getCurrentOrg(data['id'], data['collection']);
|
|
86
|
+
message = "Succesful Login";
|
|
87
|
+
document.dispatchEvent(new CustomEvent('login', {
|
|
88
|
+
detail: {}
|
|
89
|
+
}));
|
|
74
90
|
}
|
|
91
|
+
else
|
|
92
|
+
message = "The email or password you entered is incorrect";
|
|
75
93
|
|
|
76
94
|
render.data({
|
|
77
95
|
selector: "[template_id='login']",
|
|
78
|
-
data:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
data: {
|
|
97
|
+
type: 'login',
|
|
98
|
+
status,
|
|
99
|
+
message,
|
|
100
|
+
success
|
|
101
|
+
}
|
|
83
102
|
});
|
|
84
|
-
|
|
85
103
|
},
|
|
86
104
|
|
|
87
105
|
getCurrentOrg: function(user_id, collection) {
|
|
@@ -102,7 +120,7 @@ const CoCreateUser = {
|
|
|
102
120
|
window.localStorage.setItem('adminUI_id', data['adminUI_id']);
|
|
103
121
|
window.localStorage.setItem('builderUI_id', data['builderUI_id']);
|
|
104
122
|
|
|
105
|
-
document.dispatchEvent(new CustomEvent('
|
|
123
|
+
document.dispatchEvent(new CustomEvent('logIn'));
|
|
106
124
|
},
|
|
107
125
|
|
|
108
126
|
logout: (btn) => {
|
|
@@ -111,35 +129,35 @@ const CoCreateUser = {
|
|
|
111
129
|
|
|
112
130
|
let allCookies = document.cookie.split(';');
|
|
113
131
|
|
|
114
|
-
for(var i = 0; i < allCookies.length; i++)
|
|
132
|
+
for (var i = 0; i < allCookies.length; i++)
|
|
115
133
|
document.cookie = allCookies[i] + "=;expires=" +
|
|
116
134
|
new Date(0).toUTCString();
|
|
117
135
|
|
|
118
136
|
// Todo: replace with Custom event system
|
|
119
|
-
document.dispatchEvent(new CustomEvent('
|
|
137
|
+
document.dispatchEvent(new CustomEvent('logout'));
|
|
120
138
|
},
|
|
121
139
|
|
|
122
140
|
initChangeOrg: () => {
|
|
123
141
|
const user_id = window.localStorage.getItem('user_id');
|
|
124
142
|
|
|
125
|
-
if(!user_id) return;
|
|
143
|
+
if (!user_id) return;
|
|
126
144
|
|
|
127
145
|
let orgChangers = document.querySelectorAll('.org-changer');
|
|
128
146
|
|
|
129
|
-
for(let i = 0; i < orgChangers.length; i++) {
|
|
147
|
+
for (let i = 0; i < orgChangers.length; i++) {
|
|
130
148
|
let orgChanger = orgChangers[i];
|
|
131
149
|
|
|
132
150
|
const collection = orgChanger.getAttribute('collection') ? orgChanger.getAttribute('collection') : 'module_activity';
|
|
133
151
|
const id = orgChanger.getAttribute('document_id');
|
|
134
152
|
|
|
135
|
-
if(collection == 'users' && id == user_id) {
|
|
153
|
+
if (collection == 'users' && id == user_id) {
|
|
136
154
|
orgChanger.addEventListener('selectedValue', function(e) {
|
|
137
155
|
|
|
138
156
|
setTimeout(function() {
|
|
139
157
|
getCurrentOrg(user_id);
|
|
140
158
|
|
|
141
159
|
var timer = setInterval(function() {
|
|
142
|
-
if(updatedCurrentOrg) {
|
|
160
|
+
if (updatedCurrentOrg) {
|
|
143
161
|
window.location.reload();
|
|
144
162
|
|
|
145
163
|
clearInterval(timer);
|
|
@@ -154,12 +172,12 @@ const CoCreateUser = {
|
|
|
154
172
|
checkSession: () => {
|
|
155
173
|
let user_id = window.localStorage.getItem('user_id');
|
|
156
174
|
let token = window.localStorage.getItem('token');
|
|
157
|
-
if(user_id && token) {
|
|
175
|
+
if (user_id && token) {
|
|
158
176
|
let redirectTag = document.querySelector('[session="true"]');
|
|
159
177
|
|
|
160
|
-
if(redirectTag) {
|
|
178
|
+
if (redirectTag) {
|
|
161
179
|
let redirectLink = redirectTag.getAttribute('href');
|
|
162
|
-
if(redirectLink) {
|
|
180
|
+
if (redirectLink) {
|
|
163
181
|
document.location.href = redirectLink;
|
|
164
182
|
}
|
|
165
183
|
}
|
|
@@ -167,9 +185,9 @@ const CoCreateUser = {
|
|
|
167
185
|
else {
|
|
168
186
|
let redirectTag = document.querySelector('[session="false"]');
|
|
169
187
|
|
|
170
|
-
if(redirectTag) {
|
|
188
|
+
if (redirectTag) {
|
|
171
189
|
let redirectLink = redirectTag.getAttribute('href');
|
|
172
|
-
if(redirectLink) {
|
|
190
|
+
if (redirectLink) {
|
|
173
191
|
window.localStorage.clear();
|
|
174
192
|
// this.deleteCookie();
|
|
175
193
|
document.location.href = redirectLink;
|
|
@@ -185,8 +203,8 @@ const CoCreateUser = {
|
|
|
185
203
|
let data_permission = tag.getAttribute('data-permission');
|
|
186
204
|
let userPermission = data['permission-' + module_id];
|
|
187
205
|
|
|
188
|
-
if(userPermission.indexOf(data_permission) == -1) {
|
|
189
|
-
switch(data_permission) {
|
|
206
|
+
if (userPermission.indexOf(data_permission) == -1) {
|
|
207
|
+
switch (data_permission) {
|
|
190
208
|
case 'create':
|
|
191
209
|
tag.style.display = 'none';
|
|
192
210
|
break;
|
|
@@ -204,7 +222,7 @@ const CoCreateUser = {
|
|
|
204
222
|
}
|
|
205
223
|
}
|
|
206
224
|
else {
|
|
207
|
-
switch(data_permission) {
|
|
225
|
+
switch (data_permission) {
|
|
208
226
|
|
|
209
227
|
// code
|
|
210
228
|
}
|
|
@@ -213,7 +231,7 @@ const CoCreateUser = {
|
|
|
213
231
|
},
|
|
214
232
|
|
|
215
233
|
changedUserStatus: (data) => {
|
|
216
|
-
if(!data.user_id) {
|
|
234
|
+
if (!data.user_id) {
|
|
217
235
|
return;
|
|
218
236
|
}
|
|
219
237
|
let statusEls = document.querySelectorAll(`[user-status][document_id='${data['user_id']}']`);
|
|
@@ -225,12 +243,12 @@ const CoCreateUser = {
|
|
|
225
243
|
|
|
226
244
|
setDocumentId: function(collection, id) {
|
|
227
245
|
let orgIdElements = document.querySelectorAll(`[collection='${collection}']`);
|
|
228
|
-
if(orgIdElements && orgIdElements.length > 0) {
|
|
246
|
+
if (orgIdElements && orgIdElements.length > 0) {
|
|
229
247
|
orgIdElements.forEach((el) => {
|
|
230
|
-
if(!el.getAttribute('document_id')) {
|
|
248
|
+
if (!el.getAttribute('document_id')) {
|
|
231
249
|
el.setAttribute('document_id', id);
|
|
232
250
|
}
|
|
233
|
-
if(el.getAttribute('name') == "_id") {
|
|
251
|
+
if (el.getAttribute('name') == "_id") {
|
|
234
252
|
el.value = id;
|
|
235
253
|
}
|
|
236
254
|
});
|
|
@@ -239,7 +257,7 @@ const CoCreateUser = {
|
|
|
239
257
|
|
|
240
258
|
createUserNew: function(btn) {
|
|
241
259
|
let form = btn.closest("form");
|
|
242
|
-
if(!form) return;
|
|
260
|
+
if (!form) return;
|
|
243
261
|
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
244
262
|
let user_id = form.querySelector("input[collection='users'][name='_id']");
|
|
245
263
|
|
|
@@ -257,12 +275,12 @@ const CoCreateUser = {
|
|
|
257
275
|
|
|
258
276
|
createUser: function(btn) {
|
|
259
277
|
let form = btn.closest("form");
|
|
260
|
-
if(!form) return;
|
|
278
|
+
if (!form) return;
|
|
261
279
|
let org_id = "";
|
|
262
280
|
let elements = form.querySelectorAll("[collection='users'][name]");
|
|
263
281
|
let orgIdElement = form.querySelector("input[collection='organizations'][name='_id']");
|
|
264
282
|
|
|
265
|
-
if(orgIdElement) {
|
|
283
|
+
if (orgIdElement) {
|
|
266
284
|
org_id = orgIdElement.value;
|
|
267
285
|
}
|
|
268
286
|
let data = {};
|
|
@@ -270,9 +288,9 @@ const CoCreateUser = {
|
|
|
270
288
|
elements.forEach(el => {
|
|
271
289
|
let name = el.getAttribute('name');
|
|
272
290
|
let value = input.getValue(el) || el.getAttribute('value');
|
|
273
|
-
if(!name || !value) return;
|
|
291
|
+
if (!name || !value) return;
|
|
274
292
|
|
|
275
|
-
if(el.getAttribute('data-type') == 'array') {
|
|
293
|
+
if (el.getAttribute('data-type') == 'array') {
|
|
276
294
|
value = [value];
|
|
277
295
|
}
|
|
278
296
|
data[name] = value;
|
|
@@ -300,7 +318,7 @@ export default CoCreateUser;
|
|
|
300
318
|
|
|
301
319
|
action.init({
|
|
302
320
|
action: "createUserNew",
|
|
303
|
-
endEvent: "
|
|
321
|
+
endEvent: "createUserNew",
|
|
304
322
|
callback: (btn, data) => {
|
|
305
323
|
CoCreateUser.createUser(btn);
|
|
306
324
|
},
|
|
@@ -308,7 +326,7 @@ action.init({
|
|
|
308
326
|
|
|
309
327
|
action.init({
|
|
310
328
|
action: "createUser",
|
|
311
|
-
endEvent: "
|
|
329
|
+
endEvent: "createUser",
|
|
312
330
|
callback: (btn, data) => {
|
|
313
331
|
CoCreateUser.createUser(btn);
|
|
314
332
|
},
|
|
@@ -316,7 +334,7 @@ action.init({
|
|
|
316
334
|
|
|
317
335
|
action.init({
|
|
318
336
|
action: "login",
|
|
319
|
-
endEvent: "
|
|
337
|
+
endEvent: "login",
|
|
320
338
|
callback: (btn, data) => {
|
|
321
339
|
CoCreateUser.requestLogin(btn, data);
|
|
322
340
|
},
|
|
@@ -324,7 +342,7 @@ action.init({
|
|
|
324
342
|
|
|
325
343
|
action.init({
|
|
326
344
|
action: "logout",
|
|
327
|
-
endEvent: "
|
|
345
|
+
endEvent: "logout",
|
|
328
346
|
callback: (btn, data) => {
|
|
329
347
|
CoCreateUser.logout(btn, data);
|
|
330
348
|
},
|