rez_core 2.2.94 → 2.2.96
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/.vscode/extensions.json +5 -0
- package/dist/module/meta/service/entity-service-impl.service.d.ts +1 -0
- package/dist/module/meta/service/entity-service-impl.service.js +3 -0
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/notification/service/otp.service.d.ts +5 -1
- package/dist/module/notification/service/otp.service.js +34 -21
- package/dist/module/notification/service/otp.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/service/entity-service-impl.service.ts +12 -0
- package/src/module/notification/service/otp.service.ts +44 -24
package/package.json
CHANGED
|
@@ -462,6 +462,18 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
462
462
|
);
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
async getSingleResolvedData(
|
|
466
|
+
loggedInUser: UserData,
|
|
467
|
+
entityData: any,
|
|
468
|
+
entityType: string,
|
|
469
|
+
): Promise<any> {
|
|
470
|
+
return this.resolverService.getResolvedData(
|
|
471
|
+
loggedInUser,
|
|
472
|
+
entityData,
|
|
473
|
+
entityType,
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
465
477
|
async getResolvedEntityData(
|
|
466
478
|
entityType: string,
|
|
467
479
|
entityId: number,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
1
2
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
3
|
import { ConfigService } from '@nestjs/config';
|
|
3
4
|
import { ClockIDGenService } from '../../../utils/service/clockIDGenUtil.service';
|
|
4
5
|
import { Otp } from '../entity/otp.entity';
|
|
5
6
|
import { OtpRepository } from '../repository/otp.repository';
|
|
6
7
|
import { LoginService } from './../../user/service/login.service';
|
|
8
|
+
import { EmailService } from './email.service';
|
|
7
9
|
|
|
8
10
|
@Injectable()
|
|
9
11
|
export class OtpService {
|
|
@@ -12,6 +14,8 @@ export class OtpService {
|
|
|
12
14
|
private readonly idGen: ClockIDGenService,
|
|
13
15
|
private configService: ConfigService,
|
|
14
16
|
private readonly loginService: LoginService,
|
|
17
|
+
private readonly emailService: EmailService,
|
|
18
|
+
private readonly dataSource: DataSource,
|
|
15
19
|
) {}
|
|
16
20
|
|
|
17
21
|
VERIFY_OTP = this.configService.get('VERIFY_OTP') || 'true';
|
|
@@ -35,44 +39,60 @@ export class OtpService {
|
|
|
35
39
|
otp.verified = 0;
|
|
36
40
|
otp.expiration_date = new Date(Date.now() + expiresIn * 60 * 1000);
|
|
37
41
|
|
|
42
|
+
const userData = await this.dataSource
|
|
43
|
+
.getRepository('cr_user')
|
|
44
|
+
.findOne({ where: { email_id: identifier } });
|
|
45
|
+
|
|
46
|
+
const data = {
|
|
47
|
+
name: userData?.name || '',
|
|
48
|
+
otp: otp.otp,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
await this.emailService.sendEmail(identifier, 'OTP Verification', data);
|
|
52
|
+
|
|
38
53
|
return await this.otpRepository.save(otp);
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
async verifyOtp(body: { otp: string; otp_id: string; identifier: string }) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
57
|
+
const { otp, otp_id, identifier } = body;
|
|
58
|
+
const verifyOTPResponse = { isValid: false };
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
// Find OTP entity by ID
|
|
61
|
+
const otpEntity = await this.findByOtpId(otp_id);
|
|
62
|
+
if (!otpEntity) {
|
|
63
|
+
throw new BadRequestException('OTP not found!');
|
|
64
|
+
}
|
|
48
65
|
|
|
49
|
-
|
|
66
|
+
// Validate the identifier against the OTP entity
|
|
67
|
+
if (otpEntity.identifier !== identifier) {
|
|
68
|
+
throw new BadRequestException('Invalid OTP identifier!');
|
|
69
|
+
}
|
|
50
70
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
// OTP validation logic
|
|
72
|
+
const isOtpValid =
|
|
73
|
+
otpEntity.otp === otp &&
|
|
74
|
+
new Date() <= otpEntity.expiration_date &&
|
|
75
|
+
otpEntity.verified === 0;
|
|
55
76
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
otpEntity.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (updatedOtp) {
|
|
67
|
-
verifyOTPResponse.isValid = true;
|
|
68
|
-
}
|
|
77
|
+
if (isOtpValid) {
|
|
78
|
+
otpEntity.verified = 1;
|
|
79
|
+
|
|
80
|
+
// Save the updated OTP status
|
|
81
|
+
const updatedOtp = await this.otpRepository.update(
|
|
82
|
+
otpEntity.id,
|
|
83
|
+
otpEntity,
|
|
84
|
+
);
|
|
85
|
+
if (updatedOtp) {
|
|
86
|
+
verifyOTPResponse.isValid = true;
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
if (!verifyOTPResponse.isValid) {
|
|
73
91
|
throw new BadRequestException('Invalid OTP!');
|
|
74
92
|
}
|
|
75
|
-
|
|
93
|
+
|
|
94
|
+
// Proceed to login
|
|
95
|
+
return this.loginService.login(identifier, undefined, true);
|
|
76
96
|
}
|
|
77
97
|
|
|
78
98
|
async findByOtpId(otpId: string) {
|