third commit

This commit is contained in:
Дмитрий Мамедов
2026-06-10 17:01:10 +03:00
parent d393cbe1db
commit 00919968f2
21 changed files with 721 additions and 274 deletions

View File

@@ -19,6 +19,11 @@ export class VerificationService {
}
async sendEmailCode(email: string): Promise<void> {
await this.prisma.verificationCode.updateMany({
where: { target: email, usedAt: null, expiresAt: { gt: new Date() } },
data: { usedAt: new Date() },
});
const code = this.generateCode();
await this.prisma.verificationCode.create({
data: {
@@ -30,10 +35,18 @@ export class VerificationService {
},
});
await this.mailService.sendCode(email, code, 'AUTH');
this.logger.info({ email }, 'Email verification code sent');
this.logger.info(
{ target: email, channel: 'email' },
'Verification code sent',
);
}
async sendPhoneCode(phone: string): Promise<void> {
await this.prisma.verificationCode.updateMany({
where: { target: phone, usedAt: null, expiresAt: { gt: new Date() } },
data: { usedAt: new Date() },
});
const code = this.generateCode();
await this.prisma.verificationCode.create({
data: {
@@ -44,7 +57,10 @@ export class VerificationService {
expiresAt: new Date(Date.now() + 5 * 60 * 1000),
},
});
this.logger.info({ phone }, 'SMS verification code would be sent (mock)');
this.logger.info(
{ target: phone, channel: 'sms' },
'Verification code would be sent (mock)',
);
}
async verifyCode(target: string, code: string): Promise<boolean> {
@@ -59,6 +75,10 @@ export class VerificationService {
});
if (!record) {
await this.prisma.verificationCode.updateMany({
where: { target, usedAt: null, expiresAt: { gt: new Date() } },
data: { usedAt: new Date() },
});
throw new BadRequestException('Invalid or expired code');
}