@cocreate/users 1.3.2 → 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 +7 -0
- package/package.json +1 -1
- package/src/index.js +43 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.3.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.3.1...v1.3.2) (2021-10-14)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -13,6 +13,18 @@ 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() {
|
|
@@ -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
|
});
|
|
@@ -66,7 +78,7 @@ const CoCreateUser = {
|
|
|
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=/`;
|
|
@@ -75,24 +87,19 @@ const CoCreateUser = {
|
|
|
75
87
|
document.dispatchEvent(new CustomEvent('login', {
|
|
76
88
|
detail: {}
|
|
77
89
|
}));
|
|
78
|
-
|
|
79
90
|
}
|
|
80
91
|
else
|
|
81
92
|
message = "The email or password you entered is incorrect";
|
|
82
93
|
|
|
83
94
|
render.data({
|
|
84
95
|
selector: "[template_id='login']",
|
|
85
|
-
data:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
data: {
|
|
97
|
+
type: 'login',
|
|
98
|
+
status,
|
|
99
|
+
message,
|
|
100
|
+
success
|
|
101
|
+
}
|
|
91
102
|
});
|
|
92
|
-
|
|
93
|
-
document.dispatchEvent(new CustomEvent('login', {
|
|
94
|
-
detail: {}
|
|
95
|
-
}));
|
|
96
103
|
},
|
|
97
104
|
|
|
98
105
|
getCurrentOrg: function(user_id, collection) {
|
|
@@ -122,7 +129,7 @@ const CoCreateUser = {
|
|
|
122
129
|
|
|
123
130
|
let allCookies = document.cookie.split(';');
|
|
124
131
|
|
|
125
|
-
for(var i = 0; i < allCookies.length; i++)
|
|
132
|
+
for (var i = 0; i < allCookies.length; i++)
|
|
126
133
|
document.cookie = allCookies[i] + "=;expires=" +
|
|
127
134
|
new Date(0).toUTCString();
|
|
128
135
|
|
|
@@ -133,24 +140,24 @@ const CoCreateUser = {
|
|
|
133
140
|
initChangeOrg: () => {
|
|
134
141
|
const user_id = window.localStorage.getItem('user_id');
|
|
135
142
|
|
|
136
|
-
if(!user_id) return;
|
|
143
|
+
if (!user_id) return;
|
|
137
144
|
|
|
138
145
|
let orgChangers = document.querySelectorAll('.org-changer');
|
|
139
146
|
|
|
140
|
-
for(let i = 0; i < orgChangers.length; i++) {
|
|
147
|
+
for (let i = 0; i < orgChangers.length; i++) {
|
|
141
148
|
let orgChanger = orgChangers[i];
|
|
142
149
|
|
|
143
150
|
const collection = orgChanger.getAttribute('collection') ? orgChanger.getAttribute('collection') : 'module_activity';
|
|
144
151
|
const id = orgChanger.getAttribute('document_id');
|
|
145
152
|
|
|
146
|
-
if(collection == 'users' && id == user_id) {
|
|
153
|
+
if (collection == 'users' && id == user_id) {
|
|
147
154
|
orgChanger.addEventListener('selectedValue', function(e) {
|
|
148
155
|
|
|
149
156
|
setTimeout(function() {
|
|
150
157
|
getCurrentOrg(user_id);
|
|
151
158
|
|
|
152
159
|
var timer = setInterval(function() {
|
|
153
|
-
if(updatedCurrentOrg) {
|
|
160
|
+
if (updatedCurrentOrg) {
|
|
154
161
|
window.location.reload();
|
|
155
162
|
|
|
156
163
|
clearInterval(timer);
|
|
@@ -165,12 +172,12 @@ const CoCreateUser = {
|
|
|
165
172
|
checkSession: () => {
|
|
166
173
|
let user_id = window.localStorage.getItem('user_id');
|
|
167
174
|
let token = window.localStorage.getItem('token');
|
|
168
|
-
if(user_id && token) {
|
|
175
|
+
if (user_id && token) {
|
|
169
176
|
let redirectTag = document.querySelector('[session="true"]');
|
|
170
177
|
|
|
171
|
-
if(redirectTag) {
|
|
178
|
+
if (redirectTag) {
|
|
172
179
|
let redirectLink = redirectTag.getAttribute('href');
|
|
173
|
-
if(redirectLink) {
|
|
180
|
+
if (redirectLink) {
|
|
174
181
|
document.location.href = redirectLink;
|
|
175
182
|
}
|
|
176
183
|
}
|
|
@@ -178,9 +185,9 @@ const CoCreateUser = {
|
|
|
178
185
|
else {
|
|
179
186
|
let redirectTag = document.querySelector('[session="false"]');
|
|
180
187
|
|
|
181
|
-
if(redirectTag) {
|
|
188
|
+
if (redirectTag) {
|
|
182
189
|
let redirectLink = redirectTag.getAttribute('href');
|
|
183
|
-
if(redirectLink) {
|
|
190
|
+
if (redirectLink) {
|
|
184
191
|
window.localStorage.clear();
|
|
185
192
|
// this.deleteCookie();
|
|
186
193
|
document.location.href = redirectLink;
|
|
@@ -196,8 +203,8 @@ const CoCreateUser = {
|
|
|
196
203
|
let data_permission = tag.getAttribute('data-permission');
|
|
197
204
|
let userPermission = data['permission-' + module_id];
|
|
198
205
|
|
|
199
|
-
if(userPermission.indexOf(data_permission) == -1) {
|
|
200
|
-
switch(data_permission) {
|
|
206
|
+
if (userPermission.indexOf(data_permission) == -1) {
|
|
207
|
+
switch (data_permission) {
|
|
201
208
|
case 'create':
|
|
202
209
|
tag.style.display = 'none';
|
|
203
210
|
break;
|
|
@@ -215,7 +222,7 @@ const CoCreateUser = {
|
|
|
215
222
|
}
|
|
216
223
|
}
|
|
217
224
|
else {
|
|
218
|
-
switch(data_permission) {
|
|
225
|
+
switch (data_permission) {
|
|
219
226
|
|
|
220
227
|
// code
|
|
221
228
|
}
|
|
@@ -224,7 +231,7 @@ const CoCreateUser = {
|
|
|
224
231
|
},
|
|
225
232
|
|
|
226
233
|
changedUserStatus: (data) => {
|
|
227
|
-
if(!data.user_id) {
|
|
234
|
+
if (!data.user_id) {
|
|
228
235
|
return;
|
|
229
236
|
}
|
|
230
237
|
let statusEls = document.querySelectorAll(`[user-status][document_id='${data['user_id']}']`);
|
|
@@ -236,12 +243,12 @@ const CoCreateUser = {
|
|
|
236
243
|
|
|
237
244
|
setDocumentId: function(collection, id) {
|
|
238
245
|
let orgIdElements = document.querySelectorAll(`[collection='${collection}']`);
|
|
239
|
-
if(orgIdElements && orgIdElements.length > 0) {
|
|
246
|
+
if (orgIdElements && orgIdElements.length > 0) {
|
|
240
247
|
orgIdElements.forEach((el) => {
|
|
241
|
-
if(!el.getAttribute('document_id')) {
|
|
248
|
+
if (!el.getAttribute('document_id')) {
|
|
242
249
|
el.setAttribute('document_id', id);
|
|
243
250
|
}
|
|
244
|
-
if(el.getAttribute('name') == "_id") {
|
|
251
|
+
if (el.getAttribute('name') == "_id") {
|
|
245
252
|
el.value = id;
|
|
246
253
|
}
|
|
247
254
|
});
|
|
@@ -250,7 +257,7 @@ const CoCreateUser = {
|
|
|
250
257
|
|
|
251
258
|
createUserNew: function(btn) {
|
|
252
259
|
let form = btn.closest("form");
|
|
253
|
-
if(!form) return;
|
|
260
|
+
if (!form) return;
|
|
254
261
|
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
255
262
|
let user_id = form.querySelector("input[collection='users'][name='_id']");
|
|
256
263
|
|
|
@@ -268,12 +275,12 @@ const CoCreateUser = {
|
|
|
268
275
|
|
|
269
276
|
createUser: function(btn) {
|
|
270
277
|
let form = btn.closest("form");
|
|
271
|
-
if(!form) return;
|
|
278
|
+
if (!form) return;
|
|
272
279
|
let org_id = "";
|
|
273
280
|
let elements = form.querySelectorAll("[collection='users'][name]");
|
|
274
281
|
let orgIdElement = form.querySelector("input[collection='organizations'][name='_id']");
|
|
275
282
|
|
|
276
|
-
if(orgIdElement) {
|
|
283
|
+
if (orgIdElement) {
|
|
277
284
|
org_id = orgIdElement.value;
|
|
278
285
|
}
|
|
279
286
|
let data = {};
|
|
@@ -281,9 +288,9 @@ const CoCreateUser = {
|
|
|
281
288
|
elements.forEach(el => {
|
|
282
289
|
let name = el.getAttribute('name');
|
|
283
290
|
let value = input.getValue(el) || el.getAttribute('value');
|
|
284
|
-
if(!name || !value) return;
|
|
291
|
+
if (!name || !value) return;
|
|
285
292
|
|
|
286
|
-
if(el.getAttribute('data-type') == 'array') {
|
|
293
|
+
if (el.getAttribute('data-type') == 'array') {
|
|
287
294
|
value = [value];
|
|
288
295
|
}
|
|
289
296
|
data[name] = value;
|