@ubs-platform/users-webservice 6.9.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.
Files changed (108) hide show
  1. package/_monaembed/@ubs-platform/users-consts/eo-channel-consts.d.ts +13 -0
  2. package/_monaembed/@ubs-platform/users-consts/eo-channel-consts.js +18 -0
  3. package/_monaembed/@ubs-platform/users-consts/eo-channel-consts.js.map +1 -0
  4. package/_monaembed/@ubs-platform/users-consts/eo-group-event.consts.d.ts +11 -0
  5. package/_monaembed/@ubs-platform/users-consts/eo-group-event.consts.js +16 -0
  6. package/_monaembed/@ubs-platform/users-consts/eo-group-event.consts.js.map +1 -0
  7. package/_monaembed/@ubs-platform/users-consts/index.d.ts +4 -0
  8. package/_monaembed/@ubs-platform/users-consts/index.js +21 -0
  9. package/_monaembed/@ubs-platform/users-consts/index.js.map +1 -0
  10. package/_monaembed/@ubs-platform/users-consts/jwt-consts.d.ts +4 -0
  11. package/_monaembed/@ubs-platform/users-consts/jwt-consts.js +9 -0
  12. package/_monaembed/@ubs-platform/users-consts/jwt-consts.js.map +1 -0
  13. package/_monaembed/@ubs-platform/users-consts/package.json +1 -0
  14. package/_monaembed/@ubs-platform/users-consts/tsconfig.lib-publish.tsbuildinfo +1 -0
  15. package/_monaembed/@ubs-platform/users-consts/user-events.d.ts +4 -0
  16. package/_monaembed/@ubs-platform/users-consts/user-events.js +9 -0
  17. package/_monaembed/@ubs-platform/users-consts/user-events.js.map +1 -0
  18. package/dto/email.dto.d.ts +7 -0
  19. package/dto/email.dto.js +3 -0
  20. package/dto/email.dto.js.map +1 -0
  21. package/guard/jwt-local.guard.d.ts +4 -0
  22. package/guard/jwt-local.guard.js +8 -0
  23. package/guard/jwt-local.guard.js.map +1 -0
  24. package/guard/user-intercept.d.ts +5 -0
  25. package/guard/user-intercept.js +23 -0
  26. package/guard/user-intercept.js.map +1 -0
  27. package/index.d.ts +25 -0
  28. package/index.js +42 -0
  29. package/index.js.map +1 -0
  30. package/local-current-user-decorator.d.ts +1 -0
  31. package/local-current-user-decorator.js +6 -0
  32. package/local-current-user-decorator.js.map +1 -0
  33. package/mapper/entity-ownership-group.mapper.d.ts +16 -0
  34. package/mapper/entity-ownership-group.mapper.js +61 -0
  35. package/mapper/entity-ownership-group.mapper.js.map +1 -0
  36. package/mapper/entity-ownership.mapper.d.ts +15 -0
  37. package/mapper/entity-ownership.mapper.js +79 -0
  38. package/mapper/entity-ownership.mapper.js.map +1 -0
  39. package/mapper/user.mapper.d.ts +17 -0
  40. package/mapper/user.mapper.js +163 -0
  41. package/mapper/user.mapper.js.map +1 -0
  42. package/package.json +1 -0
  43. package/services/auth.service.d.ts +12 -0
  44. package/services/auth.service.js +60 -0
  45. package/services/auth.service.js.map +1 -0
  46. package/services/email-change-request.service.d.ts +16 -0
  47. package/services/email-change-request.service.js +97 -0
  48. package/services/email-change-request.service.js.map +1 -0
  49. package/services/email.service.d.ts +8 -0
  50. package/services/email.service.js +43 -0
  51. package/services/email.service.js.map +1 -0
  52. package/services/entity-ownership-group.service.d.ts +48 -0
  53. package/services/entity-ownership-group.service.js +345 -0
  54. package/services/entity-ownership-group.service.js.map +1 -0
  55. package/services/entity-ownership.service.d.ts +36 -0
  56. package/services/entity-ownership.service.js +322 -0
  57. package/services/entity-ownership.service.js.map +1 -0
  58. package/services/password-reset.service.d.ts +15 -0
  59. package/services/password-reset.service.js +113 -0
  60. package/services/password-reset.service.js.map +1 -0
  61. package/services/user-common.service.d.ts +9 -0
  62. package/services/user-common.service.js +53 -0
  63. package/services/user-common.service.js.map +1 -0
  64. package/services/user-register.service.d.ts +20 -0
  65. package/services/user-register.service.js +137 -0
  66. package/services/user-register.service.js.map +1 -0
  67. package/services/user.service.d.ts +45 -0
  68. package/services/user.service.js +279 -0
  69. package/services/user.service.js.map +1 -0
  70. package/strategies/jwt-local-strategy.d.ts +11 -0
  71. package/strategies/jwt-local-strategy.js +37 -0
  72. package/strategies/jwt-local-strategy.js.map +1 -0
  73. package/users-webservice.module.d.ts +2 -0
  74. package/users-webservice.module.js +79 -0
  75. package/users-webservice.module.js.map +1 -0
  76. package/util/crypto-op.d.ts +4 -0
  77. package/util/crypto-op.js +15 -0
  78. package/util/crypto-op.js.map +1 -0
  79. package/web/auth.controller.d.ts +11 -0
  80. package/web/auth.controller.js +83 -0
  81. package/web/auth.controller.js.map +1 -0
  82. package/web/entity-ownership-group-member.controller.d.ts +17 -0
  83. package/web/entity-ownership-group-member.controller.js +161 -0
  84. package/web/entity-ownership-group-member.controller.js.map +1 -0
  85. package/web/entity-ownership-group-microservice.controller.d.ts +28 -0
  86. package/web/entity-ownership-group-microservice.controller.js +117 -0
  87. package/web/entity-ownership-group-microservice.controller.js.map +1 -0
  88. package/web/entity-ownership-group.controller.d.ts +16 -0
  89. package/web/entity-ownership-group.controller.js +148 -0
  90. package/web/entity-ownership-group.controller.js.map +1 -0
  91. package/web/entity-ownership.controller.d.ts +20 -0
  92. package/web/entity-ownership.controller.js +140 -0
  93. package/web/entity-ownership.controller.js.map +1 -0
  94. package/web/password-reset.controller.d.ts +16 -0
  95. package/web/password-reset.controller.js +61 -0
  96. package/web/password-reset.controller.js.map +1 -0
  97. package/web/user-admin.controller.d.ts +21 -0
  98. package/web/user-admin.controller.js +107 -0
  99. package/web/user-admin.controller.js.map +1 -0
  100. package/web/user-microservice.controller.d.ts +27 -0
  101. package/web/user-microservice.controller.js +81 -0
  102. package/web/user-microservice.controller.js.map +1 -0
  103. package/web/user-registration.controller.d.ts +11 -0
  104. package/web/user-registration.controller.js +67 -0
  105. package/web/user-registration.controller.js.map +1 -0
  106. package/web/user.controller.d.ts +24 -0
  107. package/web/user.controller.js +110 -0
  108. package/web/user.controller.js.map +1 -0
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var EntityOwnershipService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.EntityOwnershipService = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const mongoose_1 = require("mongoose");
19
+ const users_entity_mongo_1 = require("@ubs-platform/users-entity-mongo");
20
+ const mongoose_2 = require("@nestjs/mongoose");
21
+ const entity_ownership_mapper_1 = require("../mapper/entity-ownership.mapper");
22
+ const user_service_1 = require("./user.service");
23
+ const users_entity_mongo_2 = require("@ubs-platform/users-entity-mongo");
24
+ let EntityOwnershipService = EntityOwnershipService_1 = class EntityOwnershipService {
25
+ constructor(eoModel, eogModel, userService, mapper) {
26
+ this.eoModel = eoModel;
27
+ this.eogModel = eogModel;
28
+ this.userService = userService;
29
+ this.mapper = mapper;
30
+ this.logger = new common_1.Logger(EntityOwnershipService_1.name, {
31
+ timestamp: true,
32
+ });
33
+ }
34
+ async removeUserCapability(eo) {
35
+ const searchKeys = {
36
+ entityGroup: eo.entityGroup,
37
+ entityId: eo.entityId,
38
+ entityName: eo.entityName,
39
+ };
40
+ const updateResult = await this.eoModel.updateOne(searchKeys, {
41
+ $pull: {
42
+ userCapabilities: {
43
+ userId: eo.userId,
44
+ },
45
+ },
46
+ });
47
+ return updateResult;
48
+ }
49
+ async findEntitiesBySearchKeys(searchKeys) {
50
+ return await this.eoModel.find({ ...(searchKeys.entityId ? { entityId: searchKeys.entityId } : {}), entityGroup: searchKeys.entityGroup, entityName: searchKeys.entityName });
51
+ }
52
+ findUserCapabilityInEntity(entityOwnership, userId, capabilitiesAtLeastOne) {
53
+ if (!entityOwnership?.userCapabilities?.length)
54
+ return null;
55
+ const found = entityOwnership.userCapabilities.find((uc) => uc.userId === userId &&
56
+ (!capabilitiesAtLeastOne?.length ||
57
+ (uc.capability &&
58
+ capabilitiesAtLeastOne.includes(uc.capability))));
59
+ return found
60
+ ? { userId: found.userId, capability: found.capability }
61
+ : null;
62
+ }
63
+ async findUserCapabilityInGroup(entityOwnership, userCheck) {
64
+ if (!entityOwnership?.entityOwnershipGroupId)
65
+ return null;
66
+ const ownerShipGroup = await this.eogModel.findOne({
67
+ _id: entityOwnership.entityOwnershipGroupId,
68
+ userCapabilities: {
69
+ $elemMatch: {
70
+ userId: userCheck.userId,
71
+ entityCapabilities: {
72
+ $elemMatch: {
73
+ entityGroup: userCheck.entityGroup,
74
+ entityName: userCheck.entityName,
75
+ ...(userCheck.capabilityAtLeastOne?.length
76
+ ? {
77
+ capability: {
78
+ $in: userCheck.capabilityAtLeastOne,
79
+ },
80
+ }
81
+ : {}),
82
+ },
83
+ },
84
+ },
85
+ },
86
+ });
87
+ if (!ownerShipGroup?.userCapabilities?.length)
88
+ return null;
89
+ const userCapability = ownerShipGroup.userCapabilities.find((uc) => uc.userId === userCheck.userId);
90
+ if (!userCapability)
91
+ return null;
92
+ const entityCapabilityMatch = userCapability.entityCapabilities.find((ec) => userCheck.entityGroup === ec.entityGroup &&
93
+ userCheck.entityName === ec.entityName &&
94
+ (!userCheck.capabilityAtLeastOne?.length ||
95
+ userCheck.capabilityAtLeastOne.includes(ec.capability)));
96
+ return entityCapabilityMatch
97
+ ? {
98
+ userId: userCapability.userId,
99
+ capability: entityCapabilityMatch.capability,
100
+ }
101
+ : null;
102
+ }
103
+ async checkRoleOverride(roleOverrides, userId, capability) {
104
+ if (!roleOverrides?.length || !userId)
105
+ return null;
106
+ const user = await this.userService.findUserAuthBackend(userId);
107
+ if (!user?.roles?.length)
108
+ return null;
109
+ if (user.roles.includes('ADMIN')) {
110
+ return {
111
+ userId: user.id,
112
+ capability: capability?.toString(),
113
+ };
114
+ }
115
+ const hasOverrideRole = user.roles.some((role) => roleOverrides.includes(role));
116
+ return hasOverrideRole
117
+ ? {
118
+ userId: user.id,
119
+ capability: capability?.toString(),
120
+ }
121
+ : null;
122
+ }
123
+ async findEntityOwnershipGroupsByUser(eo) {
124
+ return await this.eogModel.find({
125
+ 'userCapabilities.userId': eo.userId,
126
+ ...(eo.capabilityAtLeastOne
127
+ ? {
128
+ 'userCapabilities.entityCapabilities': {
129
+ $elemMatch: {
130
+ capability: { $in: eo.capabilityAtLeastOne },
131
+ entityGroup: eo.entityGroup,
132
+ entityName: eo.entityName,
133
+ },
134
+ },
135
+ }
136
+ : {}),
137
+ });
138
+ }
139
+ async edit(eoDto) {
140
+ this.logger.debug('EO EDIT', eoDto.entityGroup, eoDto.entityId, eoDto.entityName);
141
+ const searchKeys = {
142
+ entityGroup: eoDto.entityGroup,
143
+ entityId: eoDto.entityId,
144
+ entityName: eoDto.entityName,
145
+ };
146
+ const foundEntities = await this.findEntitiesBySearchKeys(searchKeys);
147
+ let entity;
148
+ if (foundEntities.length > 0) {
149
+ entity = foundEntities[0];
150
+ this.mapper.toEntityEditWithMembers(entity, eoDto);
151
+ await entity.save();
152
+ }
153
+ else {
154
+ throw new Error('EntityOwnership not found for edit.');
155
+ }
156
+ }
157
+ async insert(eoDto) {
158
+ this.logger.debug('EO INSERT', eoDto.entityGroup, eoDto.entityId, eoDto.entityName);
159
+ const searchKeys = {
160
+ entityGroup: eoDto.entityGroup,
161
+ entityId: eoDto.entityId,
162
+ entityName: eoDto.entityName,
163
+ };
164
+ const foundEntities = await this.findEntitiesBySearchKeys(searchKeys);
165
+ let entity;
166
+ if (foundEntities.length > 0) {
167
+ entity = foundEntities[0];
168
+ this.mapper.toEntityEdit(entity, eoDto);
169
+ }
170
+ else {
171
+ entity = this.mapper.toEntity(eoDto);
172
+ }
173
+ await entity.save();
174
+ }
175
+ async insertUserCapability(oe) {
176
+ const hasRoleAlready = await this.findInsertedUserCapability(oe, false);
177
+ const searchKeys = {
178
+ entityGroup: oe.entityGroup,
179
+ entityId: oe.entityId,
180
+ entityName: oe.entityName,
181
+ };
182
+ if (hasRoleAlready?.userId) {
183
+ await this.updateExistingUserCapability(searchKeys, oe);
184
+ }
185
+ else {
186
+ await this.addNewUserCapability(searchKeys, oe);
187
+ }
188
+ }
189
+ async updateExistingUserCapability(searchKeys, oe) {
190
+ const updateResult = await this.eoModel.updateOne({ ...searchKeys, 'userCapabilities.userId': oe.userId }, {
191
+ $set: {
192
+ 'userCapabilities.$[related].capability': oe.capability,
193
+ },
194
+ }, { arrayFilters: [{ 'related.userId': oe.userId }] });
195
+ if (updateResult.modifiedCount === 0) {
196
+ this.logger.warn('User capability güncellenemedi:', oe);
197
+ }
198
+ }
199
+ async addNewUserCapability(searchKeys, oe) {
200
+ const foundEntities = await this.findEntitiesBySearchKeys(searchKeys);
201
+ if (foundEntities.length > 0) {
202
+ const entity = foundEntities[0];
203
+ entity.userCapabilities.push({
204
+ capability: oe.capability,
205
+ userId: oe.userId,
206
+ });
207
+ await entity.save();
208
+ }
209
+ }
210
+ async hasInsertedUserCapability(eouc, checkRoleOverride) {
211
+ const found = await this.findInsertedUserCapability(eouc, checkRoleOverride);
212
+ return !!found;
213
+ }
214
+ async findInsertedUserCapability(entityOwnershipUserCheck, checkRoleOverride) {
215
+ this.logger.debug({
216
+ cap: entityOwnershipUserCheck.capabilityAtLeastOne?.join(','),
217
+ });
218
+ const entityOwnership = (await this.findEntitiesBySearchKeys({
219
+ entityGroup: entityOwnershipUserCheck.entityGroup,
220
+ entityName: entityOwnershipUserCheck.entityName,
221
+ ...(entityOwnershipUserCheck.entityId ? { entityId: entityOwnershipUserCheck.entityId } : {}),
222
+ }))[0];
223
+ if (!entityOwnership)
224
+ return null;
225
+ let found = this.findUserCapabilityInEntity(entityOwnership, entityOwnershipUserCheck.userId, entityOwnershipUserCheck.capabilityAtLeastOne);
226
+ if (!found) {
227
+ found = await this.findUserCapabilityInGroup(entityOwnership, entityOwnershipUserCheck);
228
+ }
229
+ if (!found && checkRoleOverride) {
230
+ const roleOverrides = entityOwnership.overriderRoles ||
231
+ (await this.eogModel.findById(entityOwnership.entityOwnershipGroupId))?.overriderRoles;
232
+ if (roleOverrides?.length) {
233
+ found = await this.checkRoleOverride(roleOverrides, entityOwnershipUserCheck.userId, entityOwnershipUserCheck.capabilityAtLeastOne?.[0]);
234
+ }
235
+ }
236
+ this.logger.debug('Found capability:', found);
237
+ return found;
238
+ }
239
+ async searchByUserRaw(eo) {
240
+ const eogsByUser = await this.findEntityOwnershipGroupsByUser(eo);
241
+ this.logger.debug('EOGs by user:', eogsByUser.length);
242
+ const eos = await this.eoModel.find({
243
+ entityGroup: eo.entityGroup,
244
+ entityName: eo.entityName,
245
+ entityId: { $ne: null },
246
+ $or: [
247
+ {
248
+ userCapabilities: {
249
+ $elemMatch: {
250
+ userId: eo.userId,
251
+ ...(eo.capabilityAtLeastOne
252
+ ? {
253
+ capability: {
254
+ $in: eo.capabilityAtLeastOne,
255
+ },
256
+ }
257
+ : {}),
258
+ },
259
+ },
260
+ },
261
+ ...(eogsByUser.length
262
+ ? [
263
+ {
264
+ entityOwnershipGroupId: {
265
+ $in: eogsByUser.map((eog) => eog._id),
266
+ },
267
+ },
268
+ ]
269
+ : []),
270
+ ],
271
+ });
272
+ return eos;
273
+ }
274
+ async searchByUser(eo) {
275
+ const entityOwnerships = await this.searchByUserRaw(eo);
276
+ return entityOwnerships.map((a) => this.mapper.toDto(a));
277
+ }
278
+ async searchByEntityIdsByEogroup(eo) {
279
+ if (!eo.entityOwnershipGroupId) {
280
+ throw new Error('entityOwnershipGroupId is required for this method.');
281
+ }
282
+ const eos = await this.eoModel.find({
283
+ entityGroup: eo.entityGroup,
284
+ entityName: eo.entityName,
285
+ entityId: { $ne: null },
286
+ entityOwnershipGroupId: eo.entityOwnershipGroupId,
287
+ });
288
+ return eos.map((a) => a.entityId?.toString());
289
+ }
290
+ async hasOwnershipsByEogId(eogId) {
291
+ const eos = await this.eoModel.find({
292
+ entityOwnershipGroupId: eogId,
293
+ });
294
+ return eos?.length > 0;
295
+ }
296
+ async searchEntityIdsByUser(eo) {
297
+ const entityOwnerships = await this.searchByUserRaw(eo);
298
+ return entityOwnerships.map((a) => a.entityId.toString());
299
+ }
300
+ async search(sk) {
301
+ const entities = await this.findEntitiesBySearchKeys(sk);
302
+ console.info('Found entities:', entities.length);
303
+ return entities.map((a) => this.mapper.toDto(a));
304
+ }
305
+ async deleteOwnership(sk) {
306
+ await this.eoModel.deleteOne(sk);
307
+ }
308
+ async findRaw(searchKeys) {
309
+ return this.findEntitiesBySearchKeys(searchKeys);
310
+ }
311
+ };
312
+ exports.EntityOwnershipService = EntityOwnershipService;
313
+ exports.EntityOwnershipService = EntityOwnershipService = EntityOwnershipService_1 = __decorate([
314
+ (0, common_1.Injectable)(),
315
+ __param(0, (0, mongoose_2.InjectModel)(users_entity_mongo_1.EntityOwnership.name)),
316
+ __param(1, (0, mongoose_2.InjectModel)(users_entity_mongo_2.EntityOwnershipGroup.name)),
317
+ __metadata("design:paramtypes", [mongoose_1.Model,
318
+ mongoose_1.Model,
319
+ user_service_1.UserService,
320
+ entity_ownership_mapper_1.EntityOwnershipMapper])
321
+ ], EntityOwnershipService);
322
+ //# sourceMappingURL=entity-ownership.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-ownership.service.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/services/entity-ownership.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,uCAAiC;AACjC,yEAG0C;AAC1C,+CAA+C;AAC/C,+EAA0E;AAU1E,iDAA6C;AAE7C,yEAAwE;AAIjE,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAK/B,YAEI,OAAuC,EAEvC,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AAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,EAAyB;QAClD,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAGO,KAAK,CAAC,OAAO,CACjB,UAAiC;QAEjC,OAAO,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;CACJ,CAAA;AAzbY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAOJ,WAAA,IAAA,sBAAW,EAAC,oCAAe,CAAC,IAAI,CAAC,CAAA;IAEjC,WAAA,IAAA,sBAAW,EAAC,yCAAoB,CAAC,IAAI,CAAC,CAAA;qCADtB,gBAAK;QAEJ,gBAAK;QACF,0BAAW;QAChB,+CAAqB;GAXhC,sBAAsB,CAyblC"}
@@ -0,0 +1,15 @@
1
+ import { Model } from 'mongoose';
2
+ import { PwResetRequest } from '@ubs-platform/users-entity-mongo';
3
+ import { UserService } from './user.service';
4
+ import { EmailService } from './email.service';
5
+ export declare class PasswordResetService {
6
+ private uservice;
7
+ private passwordResetModel;
8
+ private emailService;
9
+ constructor(uservice: UserService, passwordResetModel: Model<PwResetRequest>, emailService: EmailService);
10
+ has(id: any): Promise<boolean>;
11
+ handleCron(): Promise<void>;
12
+ insertNewRequest(username: string, origin?: string): Promise<void>;
13
+ approve(pwResetId: string, newPassword: string): Promise<void>;
14
+ private sendChangePwLink;
15
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PasswordResetService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const mongoose_1 = require("@nestjs/mongoose");
18
+ const mongoose_2 = require("mongoose");
19
+ const users_entity_mongo_1 = require("@ubs-platform/users-entity-mongo");
20
+ const user_service_1 = require("./user.service");
21
+ const email_service_1 = require("./email.service");
22
+ const schedule_1 = require("@nestjs/schedule");
23
+ let PasswordResetService = class PasswordResetService {
24
+ constructor(uservice, passwordResetModel, emailService) {
25
+ this.uservice = uservice;
26
+ this.passwordResetModel = passwordResetModel;
27
+ this.emailService = emailService;
28
+ }
29
+ async has(id) {
30
+ return ((await this.passwordResetModel.countDocuments({
31
+ _id: id,
32
+ expireAfter: {
33
+ $gt: new Date(),
34
+ },
35
+ })) > 0);
36
+ }
37
+ async handleCron() {
38
+ await this.passwordResetModel.deleteMany({
39
+ expireAfter: { $lt: new Date().toISOString() },
40
+ });
41
+ }
42
+ async insertNewRequest(username, origin) {
43
+ const EXPIRE_AFTER = 120;
44
+ const u = await this.uservice.findUserByLogin({
45
+ login: username,
46
+ password: '',
47
+ });
48
+ await this.passwordResetModel
49
+ .deleteMany({
50
+ $or: [
51
+ {
52
+ expireAfter: {
53
+ $lt: new Date(),
54
+ },
55
+ },
56
+ u?.id
57
+ ? {
58
+ userId: u.id,
59
+ }
60
+ : null,
61
+ ].filter((a) => a),
62
+ })
63
+ .exec();
64
+ if (u) {
65
+ console.info(u);
66
+ const exp = new Date();
67
+ exp.setMinutes(exp.getMinutes() + EXPIRE_AFTER);
68
+ let ech = new this.passwordResetModel();
69
+ ech.expireAfter = exp;
70
+ ech.userId = u.id;
71
+ ech = await ech.save();
72
+ this.sendChangePwLink(u, origin, ech._id);
73
+ }
74
+ }
75
+ async approve(pwResetId, newPassword) {
76
+ const exist = await this.passwordResetModel.findOne({
77
+ _id: pwResetId,
78
+ expireAfter: {
79
+ $gt: new Date(),
80
+ },
81
+ });
82
+ console.info('Current email change refresh', exist);
83
+ if (exist) {
84
+ console.info(exist.userId);
85
+ await this.uservice.changePasswordForgor(exist.userId, newPassword);
86
+ await this.passwordResetModel.deleteOne({ _id: exist.id });
87
+ }
88
+ else {
89
+ throw new common_1.HttpException('No records found', 404);
90
+ }
91
+ }
92
+ sendChangePwLink(u, origin, echId) {
93
+ this.emailService.sendEmail(u, 'password-reset-short', 'ubs-pwreset', {
94
+ link: origin +
95
+ process.env['U_USERS_PW_RESET_URL']?.replace(':id', echId),
96
+ });
97
+ }
98
+ };
99
+ exports.PasswordResetService = PasswordResetService;
100
+ __decorate([
101
+ (0, schedule_1.Cron)('* */5 * * * *'),
102
+ __metadata("design:type", Function),
103
+ __metadata("design:paramtypes", []),
104
+ __metadata("design:returntype", Promise)
105
+ ], PasswordResetService.prototype, "handleCron", null);
106
+ exports.PasswordResetService = PasswordResetService = __decorate([
107
+ (0, common_1.Injectable)(),
108
+ __param(1, (0, mongoose_1.InjectModel)(users_entity_mongo_1.PwResetRequest.name)),
109
+ __metadata("design:paramtypes", [user_service_1.UserService,
110
+ mongoose_2.Model,
111
+ email_service_1.EmailService])
112
+ ], PasswordResetService);
113
+ //# sourceMappingURL=password-reset.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset.service.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/services/password-reset.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,+CAA+C;AAC/C,uCAAiC;AAE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;IACL,CAAC;IAEO,gBAAgB,CAAC,CAAU,EAAE,MAAc,EAAE,KAAa;QAC9D,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,sBAAsB,EAAE,aAAa,EAAE;YAClE,IAAI,EACA,MAAM;gBACN,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACjE,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AA7FY,oDAAoB;AAsBvB;IADL,IAAA,eAAI,EAAC,eAAe,CAAC;;;;sDAKrB;+BA1BQ,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,sBAAW,EAAC,mCAAc,CAAC,IAAI,CAAC,CAAA;qCADf,0BAAW;QAED,gBAAK;QACX,4BAAY;GAL7B,oBAAoB,CA6FhC"}
@@ -0,0 +1,9 @@
1
+ import { UserDTO, UserCreateDTO, UserRegisterDTO } from '@ubs-platform/users-common';
2
+ import { User } from '@ubs-platform/users-entity-mongo';
3
+ import { Model } from 'mongoose';
4
+ export declare class UserCommonService {
5
+ private userModel;
6
+ constructor(userModel: Model<User>);
7
+ findByUsernameOrEmail(username: string, email: string): Promise<UserDTO[]>;
8
+ assertUserInfoValid(user: UserDTO | UserCreateDTO | UserRegisterDTO): Promise<void>;
9
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.UserCommonService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const mongoose_1 = require("@nestjs/mongoose");
18
+ const users_common_1 = require("@ubs-platform/users-common");
19
+ const users_entity_mongo_1 = require("@ubs-platform/users-entity-mongo");
20
+ const mongoose_2 = require("mongoose");
21
+ const user_mapper_1 = require("../mapper/user.mapper");
22
+ let UserCommonService = class UserCommonService {
23
+ constructor(userModel) {
24
+ this.userModel = userModel;
25
+ }
26
+ async findByUsernameOrEmail(username, email) {
27
+ const us = await this.userModel.find({
28
+ $or: [{ username: username }, { primaryEmail: email }],
29
+ });
30
+ return user_mapper_1.UserMapper.toDtoList(us);
31
+ }
32
+ async assertUserInfoValid(user) {
33
+ if (!user || !user.username || !user.primaryEmail) {
34
+ throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.EMPTY_DATA, 'One or More Required informations are empty.');
35
+ }
36
+ const userWithPrimaryMail = await this.findByUsernameOrEmail(user.username, user.primaryEmail);
37
+ if (userWithPrimaryMail.length) {
38
+ if (userWithPrimaryMail[0].username == user.username) {
39
+ throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.EXIST_USERNAME, 'User with that login is exist.');
40
+ }
41
+ else {
42
+ throw new users_common_1.ErrorInformations(users_common_1.UBSUsersErrorConsts.EXIST_PRIMARY_MAIL, 'User with that primary mail is exist.');
43
+ }
44
+ }
45
+ }
46
+ };
47
+ exports.UserCommonService = UserCommonService;
48
+ exports.UserCommonService = UserCommonService = __decorate([
49
+ (0, common_1.Injectable)(),
50
+ __param(0, (0, mongoose_1.InjectModel)(users_entity_mongo_1.User.name)),
51
+ __metadata("design:paramtypes", [mongoose_2.Model])
52
+ ], UserCommonService);
53
+ //# sourceMappingURL=user-common.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-common.service.js","sourceRoot":"","sources":["../../../../../../libs/users-webservice/src/services/user-common.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAC/C,6DAMoC;AACpC,yEAAwD;AAExD,uCAAiC;AACjC,uDAAmD;AAE5C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B,YAA4C,SAAsB;QAAtB,cAAS,GAAT,SAAS,CAAa;IAAG,CAAC;IAEtE,KAAK,CAAC,qBAAqB,CACvB,QAAgB,EAChB,KAAa;QAEb,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;SACzD,CAAC,CAAC;QACH,OAAO,wBAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAQD,KAAK,CAAC,mBAAmB,CAAC,IAA+C;QACrE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YAChD,MAAM,IAAI,gCAAiB,CACvB,kCAAmB,CAAC,UAAU,EAC9B,8CAA8C,CACjD,CAAC;QACN,CAAC;QAED,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CACxD,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,YAAY,CACpB,CAAC;QACF,IAAI,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAC7B,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnD,MAAM,IAAI,gCAAiB,CACvB,kCAAmB,CAAC,cAAc,EAClC,gCAAgC,CACnC,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,gCAAiB,CACvB,kCAAmB,CAAC,kBAAkB,EACtC,uCAAuC,CAC1C,CAAC;YACN,CAAC;QACL,CAAC;IACL,CAAC;CACJ,CAAA;AA7CY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,sBAAW,EAAC,yBAAI,CAAC,IAAI,CAAC,CAAA;qCAAoB,gBAAK;GADnD,iBAAiB,CA6C7B"}
@@ -0,0 +1,20 @@
1
+ import { EmailService } from './email.service';
2
+ import { UserCandiate } from '@ubs-platform/users-entity-mongo';
3
+ import { Model } from 'mongoose';
4
+ import { UserRegisterDTO } from '@ubs-platform/users-common';
5
+ import { UserCommonService } from './user-common.service';
6
+ import { UserService } from './user.service';
7
+ export declare class UserRegisterService {
8
+ private userCandiateModel;
9
+ private userService;
10
+ private emailService;
11
+ private userCommon;
12
+ constructor(userCandiateModel: Model<UserCandiate>, userService: UserService, emailService: EmailService, userCommon: UserCommonService);
13
+ handleCron(): Promise<void>;
14
+ sendRegisteredEmail(u: UserCandiate, key: string, origin?: string): Promise<void>;
15
+ enableUser(activationKey: string): Promise<void>;
16
+ renewOrCheckOld(id?: string): Promise<UserRegisterDTO>;
17
+ register(uregister: UserRegisterDTO, origin: string): Promise<UserRegisterDTO>;
18
+ private setExpireDate;
19
+ assertUserInfoValid(uregister: UserRegisterDTO): Promise<void>;
20
+ }