用户静默注册

This commit is contained in:
2026-07-01 02:48:59 +08:00
parent d3dd3a0ad1
commit 9f4577d3d8
18 changed files with 912 additions and 93 deletions
@@ -1,7 +1,15 @@
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import type { Request } from 'express';
import { AuthService } from './auth.service';
import { LoginSmsDto, SendSmsDto } from './dto/auth.dto';
import {
BindPhoneDto,
BootstrapSessionDto,
LoginSmsDto,
RefreshTokenDto,
SendSmsDto,
} from './dto/auth.dto';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { OptionalJwtAuthGuard } from '../../common/guards/optional-jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { AuthUser } from '../../common/guards/jwt-auth.guard';
import { ClientApp } from '@dukang/shared-types';
@@ -10,14 +18,33 @@ import { ClientApp } from '@dukang/shared-types';
export class UserAuthController {
constructor(private readonly authService: AuthService) {}
@Post('auth/session/bootstrap')
bootstrap(@Body() dto: BootstrapSessionDto) {
return this.authService.bootstrapSession(dto.deviceKey, ClientApp.USER_H5);
}
@Post('auth/token/refresh')
refresh(@Body() dto: RefreshTokenDto) {
return this.authService.refreshAccessToken(dto.refreshToken, ClientApp.USER_H5);
}
@Post('auth/sms/send')
sendSms(@Body() dto: SendSmsDto) {
return this.authService.sendSms(dto.phone, dto.scene);
}
@Post('auth/login/sms')
login(@Body() dto: LoginSmsDto) {
return this.authService.loginUser(dto.phone, dto.code, ClientApp.USER_H5);
@UseGuards(OptionalJwtAuthGuard)
login(@Req() req: Request, @Body() dto: LoginSmsDto) {
const guest = (req as Request & { user?: AuthUser }).user;
const guestId = guest?.actorType === 'USER' ? guest.actorId : undefined;
return this.authService.loginUser(dto.phone, dto.code, ClientApp.USER_H5, guestId);
}
@Post('auth/phone/bind')
@UseGuards(JwtAuthGuard)
bindPhone(@CurrentUser() user: AuthUser, @Body() dto: BindPhoneDto) {
return this.authService.bindPhone(user.actorId, dto.phone, dto.code, ClientApp.USER_H5);
}
@Post('auth/login/wechat')
@@ -26,7 +53,7 @@ export class UserAuthController {
}
@Post('auth/wechat/bind-phone')
bindPhone() {
bindPhoneLegacy() {
return this.authService.wechatDisabled();
}