@cocreate/users 1.37.6 → 1.38.1
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 +20 -0
- package/docs/index.html +323 -328
- package/package.json +1 -1
- package/prettier.config.js +16 -0
- package/src/server.js +420 -382
package/src/server.js
CHANGED
|
@@ -1,48 +1,54 @@
|
|
|
1
1
|
class CoCreateUser {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
2
|
+
constructor(crud) {
|
|
3
|
+
this.wsManager = crud.wsManager;
|
|
4
|
+
this.crud = crud;
|
|
5
|
+
this.init();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
init() {
|
|
9
|
+
if (this.wsManager) {
|
|
10
|
+
this.wsManager.on("signUp", (data) => this.signUp(data));
|
|
11
|
+
this.wsManager.on("signIn", (data) => this.signIn(data));
|
|
12
|
+
this.wsManager.on("userStatus", (data) => this.userStatus(data));
|
|
13
|
+
this.wsManager.on("checkSession", (data) =>
|
|
14
|
+
this.checkSession(data)
|
|
15
|
+
);
|
|
16
|
+
this.wsManager.on("inviteUser", (data) => this.inviteUser(data));
|
|
17
|
+
this.wsManager.on("acceptInvite", (data) =>
|
|
18
|
+
this.acceptInvite(data)
|
|
19
|
+
);
|
|
20
|
+
this.wsManager.on("forgotPassword", (data) =>
|
|
21
|
+
this.forgotPassword(data)
|
|
22
|
+
);
|
|
23
|
+
this.wsManager.on("resetPassword", (data) =>
|
|
24
|
+
this.resetPassword(data)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async signUp(data) {
|
|
30
|
+
try {
|
|
31
|
+
if (data.user) {
|
|
32
|
+
data.user.method = "object.create";
|
|
33
|
+
data.user.host = data.host;
|
|
34
|
+
const response = await this.crud.send(data.user);
|
|
35
|
+
this.wsManager.send(response);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (data.userKey) {
|
|
39
|
+
data.userKey.method = "object.create";
|
|
40
|
+
data.userKey.host = data.host;
|
|
41
|
+
const response = await this.crud.send(data.userKey);
|
|
42
|
+
this.wsManager.send(response);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.wsManager.send(data);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.log("signup error", error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
46
52
|
data = {
|
|
47
53
|
namespace: string,
|
|
48
54
|
array: string,
|
|
@@ -52,148 +58,166 @@ class CoCreateUser {
|
|
|
52
58
|
organization_id: string
|
|
53
59
|
}
|
|
54
60
|
**/
|
|
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
|
-
|
|
61
|
+
async signIn(data) {
|
|
62
|
+
const self = this;
|
|
63
|
+
try {
|
|
64
|
+
data.method = "object.read";
|
|
65
|
+
data.array = "keys";
|
|
66
|
+
let socket = data.socket;
|
|
67
|
+
delete data.socket;
|
|
68
|
+
|
|
69
|
+
// TODO: Enforce query from array keys $filter.query = {email, phone, username, password, key }
|
|
70
|
+
// Get crud properties from returned key and enforce query $filter.query = {database, array, email, phone, username, password, key }
|
|
71
|
+
// or use webhook to update keys credintials when user updates ther user
|
|
72
|
+
// Also enforce roles by webhook else role could be spoofed,
|
|
73
|
+
// Also enforce admin privlige
|
|
74
|
+
|
|
75
|
+
this.crud.send(data).then(async (data) => {
|
|
76
|
+
let response = {
|
|
77
|
+
socket,
|
|
78
|
+
host: data.host,
|
|
79
|
+
method: "signIn",
|
|
80
|
+
success: false,
|
|
81
|
+
message: "signIn failed",
|
|
82
|
+
userStatus: "off",
|
|
83
|
+
organization_id: data.organization_id,
|
|
84
|
+
uid: data.uid
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
data.object[0] &&
|
|
89
|
+
data.object[0]._id &&
|
|
90
|
+
self.wsManager.authenticate
|
|
91
|
+
) {
|
|
92
|
+
const user_id = data.object[0].key;
|
|
93
|
+
// TODO: get key to then get crud properties from key to intiate signin
|
|
94
|
+
// const { storage, database, array, key } = data.object[0];
|
|
95
|
+
// data = await this.crud.send(data);
|
|
96
|
+
const token = self.wsManager.authenticate.encodeToken(
|
|
97
|
+
data.organization_id,
|
|
98
|
+
user_id,
|
|
99
|
+
data.clientId
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if (token && token != "null") {
|
|
103
|
+
socket.user_id = user_id;
|
|
104
|
+
response.success = true;
|
|
105
|
+
response.message = "signIn successful";
|
|
106
|
+
response.userStatus = "on";
|
|
107
|
+
response.user_id = user_id;
|
|
108
|
+
response.token = token;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
self.wsManager.send(response);
|
|
112
|
+
self.wsManager.send({
|
|
113
|
+
socket,
|
|
114
|
+
host: data.host,
|
|
115
|
+
method: "updateUserStatus",
|
|
116
|
+
user_id: response.user_id,
|
|
117
|
+
userStatus: response.userStatus,
|
|
118
|
+
organization_id: response.organization_id
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.log("signIn failed", error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* status: 'on/off/idle'
|
|
128
|
+
*/
|
|
129
|
+
async userStatus(data) {
|
|
130
|
+
const self = this;
|
|
131
|
+
try {
|
|
132
|
+
if (data.user_id && data.userStatus) {
|
|
133
|
+
data.array = "users";
|
|
134
|
+
data["object"] = {
|
|
135
|
+
_id: data.user_id,
|
|
136
|
+
userStatus: data.userStatus
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
data.method = "object.update";
|
|
140
|
+
data = await this.crud.send(data);
|
|
141
|
+
|
|
142
|
+
if (data.socket)
|
|
143
|
+
self.wsManager.send({
|
|
144
|
+
socket: data.socket,
|
|
145
|
+
method: "updateUserStatus",
|
|
146
|
+
host: data.host,
|
|
147
|
+
user_id: data.user_id,
|
|
148
|
+
clientId: data.clientId,
|
|
149
|
+
userStatus: data.userStatus,
|
|
150
|
+
token: data.token,
|
|
151
|
+
organization_id:
|
|
152
|
+
data.organization_id || socket.organization_id
|
|
153
|
+
});
|
|
154
|
+
} else if (data.socket)
|
|
155
|
+
data.socket.send(
|
|
156
|
+
JSON.stringify({
|
|
157
|
+
method: "updateUserStatus",
|
|
158
|
+
host: data.host,
|
|
159
|
+
user_id: data.user_id,
|
|
160
|
+
userStatus: data.userStatus,
|
|
161
|
+
clientId: data.clientId,
|
|
162
|
+
token: data.token,
|
|
163
|
+
organization_id:
|
|
164
|
+
data.organization_id || socket.organization_id
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.log("userStatus error");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async checkSession(data) {
|
|
173
|
+
try {
|
|
174
|
+
data.method = "updateUserStatus";
|
|
175
|
+
|
|
176
|
+
if (!data.socket.user_id) data.userStatus = "off";
|
|
177
|
+
else data.userStatus = "on";
|
|
178
|
+
|
|
179
|
+
this.wsManager.send(data);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.log("checkSession error");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// TODO: email or phone param refrencing the object to execute via api
|
|
186
|
+
async inviteUser(data) {
|
|
187
|
+
try {
|
|
188
|
+
const inviteId = this.crud.ObjectId().toString();
|
|
189
|
+
let uid = data.uid;
|
|
190
|
+
delete data.uid;
|
|
191
|
+
|
|
192
|
+
data.method = "object.update";
|
|
193
|
+
data.array = "users";
|
|
194
|
+
data.object = {
|
|
195
|
+
_id: data.user_id,
|
|
196
|
+
"$push.invitations": inviteId,
|
|
197
|
+
"$addToSet.members": data.email
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// TODO: upodateDB is a temp solution to by pass crud.sync clientId as all crud methods are ignored fro same clientid except for read
|
|
201
|
+
data.updateDB = true;
|
|
202
|
+
|
|
203
|
+
data = await this.crud.send(data);
|
|
204
|
+
|
|
205
|
+
let invitee = await this.crud.send({
|
|
206
|
+
method: "object.read",
|
|
207
|
+
host: data.host,
|
|
208
|
+
array: "users",
|
|
209
|
+
$filter: {
|
|
210
|
+
query: { email: data.email },
|
|
211
|
+
limit: 1
|
|
212
|
+
},
|
|
213
|
+
organization_id: data.organization_id
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
if (invitee.object[0]) {
|
|
217
|
+
invitee = invitee.object[0]._id;
|
|
218
|
+
} else invitee = "";
|
|
219
|
+
|
|
220
|
+
let htmlBody = `
|
|
197
221
|
<html>
|
|
198
222
|
<head>
|
|
199
223
|
<title>Welcome to Yellow Oracle!</title>
|
|
@@ -218,132 +242,147 @@ class CoCreateUser {
|
|
|
218
242
|
</html>
|
|
219
243
|
`;
|
|
220
244
|
|
|
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
|
-
|
|
245
|
+
let email = {
|
|
246
|
+
method: "postmark.sendEmail",
|
|
247
|
+
host: data.host,
|
|
248
|
+
postmark: {
|
|
249
|
+
From: data.from,
|
|
250
|
+
To: data.email,
|
|
251
|
+
Subject: `${data.name} has invited you to join them on Yellow Oracle`,
|
|
252
|
+
HtmlBody: htmlBody,
|
|
253
|
+
TextBody:
|
|
254
|
+
"Hello, \n\nWe received a request to reset the password for your account.If you did not make this request, please ignore this email.Otherwise, you can reset your password by copying and pasting the following link into your browser: https://example.com/reset-password\n\nThis link will expire in 24 hours for your security.\n\nNeed more help? Our support team is here for you at support@example.com.\n\nThank you for using our services!\n\nBest regards,\nThe [Your Company] Team",
|
|
255
|
+
MessageStream: "outbound"
|
|
256
|
+
},
|
|
257
|
+
organization_id: data.organization_id
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// TODO: wsManager.emit('postmark', email) needs to await response
|
|
261
|
+
this.wsManager.emit("postmark", email);
|
|
262
|
+
|
|
263
|
+
let response = {
|
|
264
|
+
socket: data.socket,
|
|
265
|
+
host: data.host,
|
|
266
|
+
method: "inviteUser",
|
|
267
|
+
success: true,
|
|
268
|
+
message: "Succesfully sent invite",
|
|
269
|
+
organization_id: data.organization_id,
|
|
270
|
+
uid
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
this.wsManager.send(response);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
data.error = error;
|
|
276
|
+
this.wsManager.send(data);
|
|
277
|
+
|
|
278
|
+
console.log("Invite User failed", error);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async acceptInvite(data) {
|
|
283
|
+
const self = this;
|
|
284
|
+
try {
|
|
285
|
+
if (!data.token || !data.user_id) {
|
|
286
|
+
// TODO: handle error
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let uid = data.uid;
|
|
291
|
+
delete data.uid;
|
|
292
|
+
|
|
293
|
+
data.method = "object.update";
|
|
294
|
+
data.array = "users";
|
|
295
|
+
data.object = {
|
|
296
|
+
"$pull.invitations": data.token,
|
|
297
|
+
"$pull.members": data.email
|
|
298
|
+
};
|
|
299
|
+
data.$filter = {
|
|
300
|
+
query: {
|
|
301
|
+
invitations: { $in: [data.token] },
|
|
302
|
+
members: { $in: [data.email] }
|
|
303
|
+
},
|
|
304
|
+
limit: 2
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// TODO: upodateDB is a temp solution to by pass crud.sync clientId as all crud methods are ignored fro same clientid except for read
|
|
308
|
+
data.updateDB = true;
|
|
309
|
+
|
|
310
|
+
data = await this.crud.send(data);
|
|
311
|
+
|
|
312
|
+
let response = {
|
|
313
|
+
socket: data.socket,
|
|
314
|
+
host: data.host,
|
|
315
|
+
method: "acceptInvite",
|
|
316
|
+
success: false,
|
|
317
|
+
message:
|
|
318
|
+
"The token is invalid or has expired. However, you can still access your account. Please request a new invite to proceed, and feel free to explore the available features while you wait.",
|
|
319
|
+
organization_id: data.organization_id,
|
|
320
|
+
uid
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
for (let object of data.object) {
|
|
324
|
+
if (object._id) {
|
|
325
|
+
delete data.$filter;
|
|
326
|
+
data.object = {
|
|
327
|
+
_id: object._id,
|
|
328
|
+
"$addToSet.members": data.user_id
|
|
329
|
+
};
|
|
330
|
+
data = await this.crud.send(data);
|
|
331
|
+
this.crud.send({
|
|
332
|
+
method: "object.update",
|
|
333
|
+
host: data.host,
|
|
334
|
+
array: "users",
|
|
335
|
+
object: {
|
|
336
|
+
_id: data.user_id,
|
|
337
|
+
memberAccount: object._id,
|
|
338
|
+
subscription: "6571fe530c48ef6970900a82"
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
response.success = true;
|
|
342
|
+
response.message = "Invite Accepted";
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
self.wsManager.send(response);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.log("Accept invite failed", error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// TODO: email or phone param refrencing the object to execute via api
|
|
354
|
+
async forgotPassword(data) {
|
|
355
|
+
const self = this;
|
|
356
|
+
try {
|
|
357
|
+
const recoveryId = this.crud.ObjectId().toString();
|
|
358
|
+
let socket = data.socket;
|
|
359
|
+
delete data.socket;
|
|
360
|
+
|
|
361
|
+
data.method = "object.update";
|
|
362
|
+
data.array = "keys";
|
|
363
|
+
data.object = { recoveryId };
|
|
364
|
+
data.$filter = {
|
|
365
|
+
query: { email: data.email },
|
|
366
|
+
limit: 1
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
this.crud.send(data).then(async (data) => {
|
|
370
|
+
let response = {
|
|
371
|
+
socket,
|
|
372
|
+
host: data.host,
|
|
373
|
+
method: "forgotPassword",
|
|
374
|
+
success: false,
|
|
375
|
+
message: "Email does not exist",
|
|
376
|
+
organization_id: data.organization_id,
|
|
377
|
+
uid: data.uid
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
for (let object of data.object) {
|
|
381
|
+
if (object._id) {
|
|
382
|
+
// TODO: sendEmail
|
|
383
|
+
response.success = true;
|
|
384
|
+
response.message = "Email Sent";
|
|
385
|
+
let htmlBody = `
|
|
347
386
|
<html>
|
|
348
387
|
<head>
|
|
349
388
|
<title>Reset Your Password</title>
|
|
@@ -366,75 +405,74 @@ class CoCreateUser {
|
|
|
366
405
|
|
|
367
406
|
</body>
|
|
368
407
|
</html>
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
}
|
|
408
|
+
`;
|
|
409
|
+
let email = {
|
|
410
|
+
method: "postmark.sendEmail",
|
|
411
|
+
host: data.host,
|
|
412
|
+
postmark: {
|
|
413
|
+
From: data.from,
|
|
414
|
+
To: data.email,
|
|
415
|
+
Subject: "Reset Your Password Easily",
|
|
416
|
+
HtmlBody: htmlBody,
|
|
417
|
+
TextBody:
|
|
418
|
+
"Hello, \n\nWe received a request to reset the password for your account. If you did not make this request, please ignore this email. Otherwise, you can reset your password by copying and pasting the following link into your browser: https://example.com/reset-password\n\nThis link will expire in 24 hours for your security.\n\nNeed more help? Our support team is here for you at support@example.com.\n\nThank you for using our services!\n\nBest regards,\nThe [Your Company] Team",
|
|
419
|
+
MessageStream: "outbound"
|
|
420
|
+
},
|
|
421
|
+
organization_id: data.organization_id
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// TODO: wsManager.emit('postmark', email) needs to await response
|
|
425
|
+
self.wsManager.emit("postmark", email);
|
|
426
|
+
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
self.wsManager.send(response);
|
|
432
|
+
});
|
|
433
|
+
} catch (error) {
|
|
434
|
+
console.log("Forgot Password failed", error);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async resetPassword(data) {
|
|
439
|
+
const self = this;
|
|
440
|
+
try {
|
|
441
|
+
if (!data.email || !data.password || !data.token) return;
|
|
442
|
+
|
|
443
|
+
data.method = "object.update";
|
|
444
|
+
data.array = "keys";
|
|
445
|
+
data.object = { password: data.password, recoveryId: "" };
|
|
446
|
+
data.$filter = {
|
|
447
|
+
query: { email: data.email, recoveryId: data.token },
|
|
448
|
+
limit: 1
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
this.crud.send(data).then(async (data) => {
|
|
452
|
+
let response = {
|
|
453
|
+
socket: data.socket,
|
|
454
|
+
host: data.host,
|
|
455
|
+
method: "resetPassword",
|
|
456
|
+
success: false,
|
|
457
|
+
message: "Token is invalid or has expired",
|
|
458
|
+
organization_id: data.organization_id,
|
|
459
|
+
uid: data.uid
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
for (let object of data.object) {
|
|
463
|
+
if (object._id) {
|
|
464
|
+
response.success = true;
|
|
465
|
+
response.message = "Password reset succesfull";
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
self.wsManager.send(response);
|
|
471
|
+
});
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.log("Password reset failed", error);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
438
476
|
}
|
|
439
477
|
|
|
440
|
-
module.exports = CoCreateUser;
|
|
478
|
+
module.exports = CoCreateUser;
|