@cocreate/users 1.27.5 → 1.27.7
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 +21 -0
- package/package.json +1 -1
- package/src/client.js +53 -73
- package/src/server.js +37 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.27.7](https://github.com/CoCreate-app/CoCreate-users/compare/v1.27.6...v1.27.7) (2023-10-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* removed console.log ([b0bbf02](https://github.com/CoCreate-app/CoCreate-users/commit/b0bbf024e88c08011388dc0e44d332ece9e9851a))
|
|
7
|
+
* removed console.log ([db03fb5](https://github.com/CoCreate-app/CoCreate-users/commit/db03fb5b8aa486582719f95e97a02b387ccbf530))
|
|
8
|
+
* removed dupilicate variable ([9015f6b](https://github.com/CoCreate-app/CoCreate-users/commit/9015f6bf8898a161daa18b342701e781b076be4b))
|
|
9
|
+
|
|
10
|
+
## [1.27.6](https://github.com/CoCreate-app/CoCreate-users/compare/v1.27.5...v1.27.6) (2023-10-19)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* data.socket not found ([0b0b1e3](https://github.com/CoCreate-app/CoCreate-users/commit/0b0b1e32546758ef0ec0782817b3d5c94c595ee5))
|
|
16
|
+
* declartion of render functions using object spread ([30f9242](https://github.com/CoCreate-app/CoCreate-users/commit/30f924235a66ce2be22a9f53d92e6425db59708e))
|
|
17
|
+
* missing await and organization_id ([df79036](https://github.com/CoCreate-app/CoCreate-users/commit/df79036e7ba786bf6698c2cad91c5bbd4f3e50b5))
|
|
18
|
+
* replaced message with socket ([5036966](https://github.com/CoCreate-app/CoCreate-users/commit/503696642d5df6c8fba76862fc59db1d010b3dea))
|
|
19
|
+
* signup ([bf716d8](https://github.com/CoCreate-app/CoCreate-users/commit/bf716d8d94cf16641e01cb3ca56f4ecbe41cebef))
|
|
20
|
+
* update to support socket ([3fdd085](https://github.com/CoCreate-app/CoCreate-users/commit/3fdd0853d83ade29069977570dcb9ad67bf17318))
|
|
21
|
+
|
|
1
22
|
## [1.27.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.27.4...v1.27.5) (2023-10-17)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/*globals CustomEvent, btoa*/
|
|
2
2
|
import Crud from '@cocreate/crud-client';
|
|
3
|
-
import
|
|
3
|
+
import Actions from '@cocreate/actions';
|
|
4
4
|
import Elements from '@cocreate/elements';
|
|
5
|
-
import
|
|
5
|
+
import { render } from '@cocreate/render';
|
|
6
6
|
import '@cocreate/element-prototype';
|
|
7
7
|
import './index.css';
|
|
8
|
+
|
|
9
|
+
// TODO: Replace with @cocreate/config
|
|
8
10
|
import localStorage from '@cocreate/local-storage';
|
|
9
11
|
|
|
10
12
|
const CoCreateUser = {
|
|
@@ -22,51 +24,43 @@ const CoCreateUser = {
|
|
|
22
24
|
Crud.listen('updateUserStatus', (data) => self.updateUserStatus(data));
|
|
23
25
|
},
|
|
24
26
|
|
|
25
|
-
signUp: async function (
|
|
26
|
-
|
|
27
|
-
if (!formEl) return;
|
|
27
|
+
signUp: async function (action) {
|
|
28
|
+
if (!action.form) return;
|
|
28
29
|
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (array)
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
30
|
+
let data = await Elements.save(action.form)
|
|
31
|
+
let user = data[0]
|
|
32
|
+
// data.method = 'create.object'
|
|
33
|
+
// data['array'] = array
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
data.method = 'create.object'
|
|
40
|
-
data['array'] = array
|
|
41
|
-
data.organization_id = organization_id;
|
|
35
|
+
// data.organization_id = organization_id;
|
|
42
36
|
|
|
43
|
-
if (!data.object[0]._id)
|
|
44
|
-
|
|
37
|
+
// if (!data.object[0]._id)
|
|
38
|
+
// data.object[0]._id = Crud.ObjectId();
|
|
45
39
|
|
|
46
|
-
let user = await Crud.send(data)
|
|
47
|
-
Elements.setTypeValue(formEl, user)
|
|
40
|
+
// let user = await Crud.send(data)
|
|
41
|
+
// Elements.setTypeValue(formEl, user)
|
|
48
42
|
|
|
49
43
|
// const socket = Crud.socket.getSockets()
|
|
50
44
|
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
51
45
|
let key = {
|
|
46
|
+
status: 'await',
|
|
52
47
|
method: 'create.object',
|
|
53
48
|
array: 'keys',
|
|
54
49
|
object: {
|
|
55
50
|
type: "user",
|
|
56
51
|
key: user.object[0]._id,
|
|
57
52
|
roles: ['user'],
|
|
58
|
-
email: user.object.email,
|
|
59
|
-
password: user.object.password || btoa('0000'),
|
|
60
|
-
array
|
|
61
|
-
}
|
|
62
|
-
organization_id
|
|
53
|
+
email: user.object[0].email,
|
|
54
|
+
password: user.object[0].password || btoa('0000'),
|
|
55
|
+
array: data.array
|
|
56
|
+
}
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
let response = await Crud.send(key)
|
|
66
60
|
if (response && response.object && response.object[0]) {
|
|
67
|
-
Crud.socket.send({ method: 'signUp', user, userKey })
|
|
61
|
+
// Crud.socket.send({ method: 'signUp', user, userKey })
|
|
68
62
|
|
|
69
|
-
|
|
63
|
+
render({
|
|
70
64
|
selector: "[template='signUp']",
|
|
71
65
|
data: {
|
|
72
66
|
type: 'signUp',
|
|
@@ -82,29 +76,26 @@ const CoCreateUser = {
|
|
|
82
76
|
}
|
|
83
77
|
},
|
|
84
78
|
|
|
85
|
-
signIn: async function (
|
|
86
|
-
|
|
87
|
-
let array = form.getAttribute('array');
|
|
79
|
+
signIn: async function (action) {
|
|
80
|
+
if (!action.form) return;
|
|
88
81
|
let query = [];
|
|
89
82
|
|
|
90
|
-
const inputs = form.querySelectorAll('input[key="email"], input[key="password"], input[key="username"]');
|
|
83
|
+
const inputs = action.form.querySelectorAll('input[key="email"], input[key="password"], input[key="username"]');
|
|
91
84
|
for (let i = 0; i < inputs.length; i++) {
|
|
92
85
|
const key = inputs[i].getAttribute('key');
|
|
93
86
|
const value = await inputs[i].getValue();
|
|
94
|
-
array = 'keys';
|
|
95
87
|
query.push({ key, value, operator: '$eq' })
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
let request = {
|
|
99
91
|
method: 'read.object',
|
|
100
|
-
|
|
101
|
-
array,
|
|
92
|
+
array: 'keys',
|
|
102
93
|
$filter: {
|
|
103
94
|
query
|
|
104
95
|
}
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
const socket = Crud.socket.getSockets()
|
|
98
|
+
const socket = await Crud.socket.getSockets()
|
|
108
99
|
if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || Crud.socket.serverOrganization == false) {
|
|
109
100
|
Crud.send(request).then((response) => {
|
|
110
101
|
response['success'] = false
|
|
@@ -129,14 +120,13 @@ const CoCreateUser = {
|
|
|
129
120
|
},
|
|
130
121
|
|
|
131
122
|
signInResponse: function (data) {
|
|
132
|
-
let { success, status, message, user_id, token } = data;
|
|
123
|
+
let { success, status, message, organization_id, user_id, token } = data;
|
|
133
124
|
if (success) {
|
|
134
125
|
localStorage.setItem('organization_id', organization_id);
|
|
135
126
|
localStorage.setItem("key", Crud.socket.key);
|
|
136
127
|
localStorage.setItem("host", Crud.socket.host);
|
|
137
128
|
localStorage.setItem('user_id', user_id);
|
|
138
129
|
localStorage.setItem("token", token);
|
|
139
|
-
// document.cookie = `token=${token};path=/`;
|
|
140
130
|
message = "Succesful signIn";
|
|
141
131
|
document.dispatchEvent(new CustomEvent('signIn', {
|
|
142
132
|
detail: {}
|
|
@@ -145,7 +135,7 @@ const CoCreateUser = {
|
|
|
145
135
|
else
|
|
146
136
|
message = "The email or password you entered is incorrect";
|
|
147
137
|
|
|
148
|
-
|
|
138
|
+
render({
|
|
149
139
|
selector: "[template='signIn']",
|
|
150
140
|
data: {
|
|
151
141
|
type: 'signIn',
|
|
@@ -156,18 +146,12 @@ const CoCreateUser = {
|
|
|
156
146
|
});
|
|
157
147
|
},
|
|
158
148
|
|
|
159
|
-
signOut: (
|
|
149
|
+
signOut: () => {
|
|
160
150
|
self = this;
|
|
161
151
|
localStorage.removeItem("user_id");
|
|
162
152
|
localStorage.removeItem("token");
|
|
163
153
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// for (var i = 0; i < allCookies.length; i++)
|
|
167
|
-
// document.cookie = allCookies[i] + "=;expires=" +
|
|
168
|
-
// new Date(0).toUTCString();
|
|
169
|
-
|
|
170
|
-
Render.data({
|
|
154
|
+
render({
|
|
171
155
|
selector: "[template='signOut']",
|
|
172
156
|
data: {
|
|
173
157
|
type: 'signOut',
|
|
@@ -214,8 +198,6 @@ const CoCreateUser = {
|
|
|
214
198
|
if (redirectLink) {
|
|
215
199
|
localStorage.removeItem("user_id");
|
|
216
200
|
localStorage.removeItem("token");
|
|
217
|
-
|
|
218
|
-
// this.deleteCookie();
|
|
219
201
|
document.location.href = redirectLink;
|
|
220
202
|
}
|
|
221
203
|
}
|
|
@@ -228,8 +210,7 @@ const CoCreateUser = {
|
|
|
228
210
|
|
|
229
211
|
if (redirectTag) {
|
|
230
212
|
Crud.socket.send({
|
|
231
|
-
method: '
|
|
232
|
-
message: 'checkSession',
|
|
213
|
+
method: 'checkSession',
|
|
233
214
|
broadcast: false,
|
|
234
215
|
broadcastSender: false,
|
|
235
216
|
broadcastBrowser: false
|
|
@@ -244,30 +225,29 @@ const CoCreateUser = {
|
|
|
244
225
|
}
|
|
245
226
|
};
|
|
246
227
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
Action.init({
|
|
257
|
-
name: "signIn",
|
|
258
|
-
endEvent: "signIn",
|
|
259
|
-
callback: (data) => {
|
|
260
|
-
CoCreateUser.signIn(data.element);
|
|
228
|
+
Actions.init([
|
|
229
|
+
{
|
|
230
|
+
name: "signUp",
|
|
231
|
+
endEvent: "signUp",
|
|
232
|
+
callback: (action) => {
|
|
233
|
+
CoCreateUser.signUp(action);
|
|
234
|
+
}
|
|
261
235
|
},
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
CoCreateUser.signOut(data.element);
|
|
236
|
+
{
|
|
237
|
+
name: "signIn",
|
|
238
|
+
endEvent: "signIn",
|
|
239
|
+
callback: (action) => {
|
|
240
|
+
CoCreateUser.signIn(action);
|
|
241
|
+
}
|
|
269
242
|
},
|
|
270
|
-
|
|
243
|
+
{
|
|
244
|
+
name: "signOut",
|
|
245
|
+
endEvent: "signOut",
|
|
246
|
+
callback: (action) => {
|
|
247
|
+
CoCreateUser.signOut(action);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
]);
|
|
271
251
|
|
|
272
252
|
CoCreateUser.init();
|
|
273
253
|
|
package/src/server.js
CHANGED
|
@@ -14,9 +14,7 @@ class CoCreateUser {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async signUp(data) {
|
|
17
|
-
const self = this;
|
|
18
17
|
try {
|
|
19
|
-
|
|
20
18
|
if (data.user) {
|
|
21
19
|
data.user.method = 'create.object'
|
|
22
20
|
const response = await this.crud.send(data.user)
|
|
@@ -29,10 +27,10 @@ class CoCreateUser {
|
|
|
29
27
|
this.wsManager.send(response);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
this.wsManager.send(data);
|
|
33
31
|
|
|
34
32
|
} catch (error) {
|
|
35
|
-
console.log('
|
|
33
|
+
console.log('signup error', error);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
|
|
@@ -51,42 +49,36 @@ class CoCreateUser {
|
|
|
51
49
|
const self = this;
|
|
52
50
|
try {
|
|
53
51
|
data.method = 'read.object'
|
|
52
|
+
let socket = data.socket
|
|
53
|
+
delete data.socket
|
|
54
|
+
|
|
54
55
|
this.crud.send(data).then(async (data) => {
|
|
55
56
|
let response = {
|
|
57
|
+
socket,
|
|
56
58
|
method: 'signIn',
|
|
57
59
|
success: false,
|
|
58
60
|
message: "signIn failed",
|
|
59
|
-
status: "failed",
|
|
60
61
|
userStatus: 'off',
|
|
62
|
+
organization_id: data.organization_id,
|
|
61
63
|
uid: data.uid
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
if (data.object[0] && data.object[0]._id && self.wsManager.authenticate) {
|
|
65
67
|
const user_id = data.object[0].key
|
|
66
|
-
const token = await self.wsManager.authenticate.
|
|
68
|
+
const token = await self.wsManager.authenticate.encodeToken({ user_id });
|
|
67
69
|
|
|
68
70
|
if (token && token != 'null') {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
token,
|
|
76
|
-
uid: data.uid
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// if (data.organization_id != process.env.organization_id) {
|
|
80
|
-
// let Data = { organization_id: process.env.organization_id }
|
|
81
|
-
// Data.object['_id'] = data.object[0]._id
|
|
82
|
-
// Data.object['lastsignIn'] = data.object[0].lastsignIn
|
|
83
|
-
// Data.object['organization_id'] = process.env.organization_id
|
|
84
|
-
// crud.send(Data)
|
|
85
|
-
// }
|
|
71
|
+
socket.user_id = user_id
|
|
72
|
+
response.success = true
|
|
73
|
+
response.message = "signIn successful"
|
|
74
|
+
response.userStatus = 'on'
|
|
75
|
+
response.user_id = user_id
|
|
76
|
+
response.token = token
|
|
86
77
|
}
|
|
87
78
|
}
|
|
88
79
|
self.wsManager.send(response)
|
|
89
80
|
self.wsManager.send({
|
|
81
|
+
socket,
|
|
90
82
|
method: 'updateUserStatus',
|
|
91
83
|
user_id: response.user_id,
|
|
92
84
|
userStatus: response.userStatus,
|
|
@@ -106,24 +98,34 @@ class CoCreateUser {
|
|
|
106
98
|
async userStatus(data) {
|
|
107
99
|
const self = this;
|
|
108
100
|
try {
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
101
|
+
if (data.user_id && data.userStatus) {
|
|
102
|
+
data.array = 'users'
|
|
103
|
+
data['object'] = {
|
|
104
|
+
_id: data.user_id,
|
|
105
|
+
userStatus: data.userStatus
|
|
106
|
+
}
|
|
116
107
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
data.method = 'update.object'
|
|
109
|
+
data = await this.crud.send(data)
|
|
110
|
+
|
|
111
|
+
if (data.socket)
|
|
112
|
+
self.wsManager.send({
|
|
113
|
+
socket: data.socket,
|
|
114
|
+
method: 'updateUserStatus',
|
|
115
|
+
user_id: data.user_id,
|
|
116
|
+
userStatus: data.userStatus,
|
|
117
|
+
token: data.token,
|
|
118
|
+
organization_id: data.organization_id || socket.organization_id
|
|
119
|
+
})
|
|
120
|
+
} else if (data.socket)
|
|
121
|
+
data.socket.send(JSON.stringify({
|
|
120
122
|
method: 'updateUserStatus',
|
|
121
123
|
user_id: data.user_id,
|
|
122
124
|
userStatus: data.userStatus,
|
|
125
|
+
token: data.token,
|
|
123
126
|
organization_id: data.organization_id || socket.organization_id
|
|
124
|
-
})
|
|
127
|
+
}))
|
|
125
128
|
|
|
126
|
-
})
|
|
127
129
|
|
|
128
130
|
} catch (error) {
|
|
129
131
|
console.log('userStatus error')
|