39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { LoginPasswordDto, LoginSmsDto, LoginWechatDto, SendSmsDto } from './dto/auth.dto';
|
|
import { JwtAuthGuard } from '../../common/guards/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';
|
|
|
|
@Controller('admin/auth')
|
|
export class AdminAuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('sms/send')
|
|
sendSms(@Body() dto: SendSmsDto) {
|
|
return this.authService.sendSms(dto.phone, dto.scene, { clientApp: ClientApp.HQ_WEB });
|
|
}
|
|
|
|
@Post('login/sms')
|
|
login(@Body() dto: LoginSmsDto) {
|
|
return this.authService.loginHq(dto.phone, dto.code, ClientApp.HQ_WEB);
|
|
}
|
|
|
|
@Post('login/password')
|
|
loginPassword(@Body() dto: LoginPasswordDto) {
|
|
return this.authService.loginHqPassword(dto.loginName, dto.password, ClientApp.HQ_WEB);
|
|
}
|
|
|
|
@Post('login/wechat')
|
|
wechatLogin(@Body() dto: LoginWechatDto) {
|
|
return this.authService.loginHqWechat(dto.code, ClientApp.HQ_WEB, dto.platform ?? 'h5');
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
me(@CurrentUser() user: AuthUser) {
|
|
return this.authService.getMe(user.actorType, user.actorId);
|
|
}
|
|
}
|