feat: 后端调整登陆逻辑
This commit is contained in:
@@ -11,24 +11,24 @@ import { Throttle, ThrottlerGuard } from '@nestjs/throttler';
|
||||
|
||||
@Controller('verification')
|
||||
export class VerificationController {
|
||||
constructor(private readonly verificationService: VerificationService) {}
|
||||
constructor(private readonly verificationService: VerificationService) { }
|
||||
|
||||
@Post('send')
|
||||
@UseGuards(ThrottlerGuard)
|
||||
@Throttle({ default: { limit: 20, ttl: 60000 } })
|
||||
async sendVerificationCode(@Body() dto: SendVerificationCodeDto) {
|
||||
switch (dto.type) {
|
||||
case 'login':
|
||||
switch (dto.targetType) {
|
||||
case 'phone':
|
||||
return this.verificationService.sendPhoneCode(dto.phone, dto.type);
|
||||
case 'email':
|
||||
return this.verificationService.sendEmailCode(dto.email, dto.type);
|
||||
default:
|
||||
throw new BadRequestException('不支持的目标类型');
|
||||
}
|
||||
default:
|
||||
throw new BadRequestException('不支持的验证码类型');
|
||||
}
|
||||
}
|
||||
// @Post('send')
|
||||
// @UseGuards(ThrottlerGuard)
|
||||
// @Throttle({ default: { limit: 20, ttl: 60000 } })
|
||||
// async sendVerificationCode(@Body() dto: SendVerificationCodeDto) {
|
||||
// switch (dto.type) {
|
||||
// case 'login':
|
||||
// switch (dto.targetType) {
|
||||
// case 'phone':
|
||||
// return this.verificationService.sendPhoneCode(dto.phone, dto.type);
|
||||
// case 'email':
|
||||
// return this.verificationService.sendEmailCode(dto.email, dto.type);
|
||||
// default:
|
||||
// throw new BadRequestException('不支持的目标类型');
|
||||
// }
|
||||
// default:
|
||||
// throw new BadRequestException('不支持的验证码类型');
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { NotificationService } from 'src/notification/notification.service';
|
||||
export class VerificationService {
|
||||
private readonly logger = new Logger(VerificationService.name);
|
||||
|
||||
constructor(private readonly notificationService: NotificationService) {}
|
||||
constructor(private readonly notificationService: NotificationService) { }
|
||||
|
||||
private pool: Map<
|
||||
string,
|
||||
@@ -121,7 +121,10 @@ export class VerificationService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private generateCode() {
|
||||
/**
|
||||
* 生成100000~999999的随机纯数字验证码
|
||||
*/
|
||||
private generateCode(): string {
|
||||
return Math.floor(100000 + Math.random() * 900000).toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user