27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { Body, Controller, Post } from '@nestjs/common';
|
||
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||
import { CoreGrpcService } from '../core-grpc.service';
|
||
import { SendOtpDto, VerifyOtpDto } from '../dto/identity.dto';
|
||
|
||
@ApiTags('OTP и 2FA')
|
||
@Controller('auth/otp')
|
||
export class OtpController {
|
||
constructor(private readonly core: CoreGrpcService) {}
|
||
|
||
@Post('send')
|
||
@ApiOperation({ summary: 'Отправить OTP код', description: 'Создает одноразовый код в AuthCode. Fallback-доставка пишет код в console.log.' })
|
||
@ApiBody({ type: SendOtpDto })
|
||
@ApiResponse({ status: 201, description: 'Код создан и отправлен' })
|
||
send(@Body() dto: SendOtpDto) {
|
||
return this.core.otp.SendOtp(dto);
|
||
}
|
||
|
||
@Post('verify')
|
||
@ApiOperation({ summary: 'Проверить OTP код', description: 'Проверяет одноразовый код, срок жизни и помечает его использованным.' })
|
||
@ApiBody({ type: VerifyOtpDto })
|
||
@ApiResponse({ status: 201, description: 'Код подтвержден' })
|
||
verify(@Body() dto: VerifyOtpDto) {
|
||
return this.core.otp.VerifyOtp(dto);
|
||
}
|
||
}
|