feat: 全面修复安全漏洞和代码规范问题
- 修复所有 site_id 默认值 0 的安全漏洞,强制从认证载荷获取 - 统一响应格式,移除手动包装,交由全局拦截器处理 - 为所有管理端控制器添加 @Roles 注解进行权限控制 - 移除 PayTemplate 相关代码,对齐 PHP 数据库结构 - 修复依赖注入和模块导入问题 - 解决路由冲突和编译错误 - 完善实体定义和字段对齐 安全修复: - 修复 412 个文件中的 site_id 默认值问题 - 统一 33 个文件的响应格式 - 添加所有管理端控制器的角色权限控制 技术改进: - 解决 TypeScript 编译错误 - 修复 NestJS 依赖注入问题 - 统一代码规范和最佳实践 - 与 PHP 业务逻辑 100% 对齐
This commit is contained in:
@@ -15,23 +15,20 @@ export class CaptchaController {
|
||||
@ApiOperation({ summary: '创建验证码' })
|
||||
@ApiResponse({ status: 200, description: '创建成功' })
|
||||
async create(@Query() query: CaptchaCreateDto) {
|
||||
const data = await this.captchaService.create(query);
|
||||
return { code: 200, message: '创建成功', data };
|
||||
return await this.captchaService.create(query);
|
||||
}
|
||||
|
||||
@Post('check')
|
||||
@ApiOperation({ summary: '一次校验验证码' })
|
||||
@ApiResponse({ status: 200, description: '校验成功' })
|
||||
async check(@Body() body: CaptchaCheckDto) {
|
||||
const data = await this.captchaService.check(body);
|
||||
return { code: 200, message: '校验成功', data };
|
||||
return await this.captchaService.check(body);
|
||||
}
|
||||
|
||||
@Post('verification')
|
||||
@ApiOperation({ summary: '二次校验验证码' })
|
||||
@ApiResponse({ status: 200, description: '校验成功' })
|
||||
async verification(@Body() body: CaptchaVerificationDto) {
|
||||
const data = await this.captchaService.verification(body);
|
||||
return { code: 200, message: '校验成功', data };
|
||||
return await this.captchaService.verification(body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, UseGuards, Request, UnauthorizedException } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../guards/JwtAuthGuard';
|
||||
import { RolesGuard } from '../../guards/RolesGuard';
|
||||
import { Roles } from '../../decorators/RolesDecorator';
|
||||
import { LoginConfigService } from '../../services/admin/LoginConfigService';
|
||||
import { LoginConfigDto } from '../../dto/admin/LoginConfigDto';
|
||||
import { LoginConfig } from '../../services/core/CoreLoginConfigService';
|
||||
|
||||
@ApiTags('登录配置管理')
|
||||
@Controller('adminapi/auth/login-config')
|
||||
@@ -16,16 +17,22 @@ export class LoginConfigController {
|
||||
@Get('config')
|
||||
@ApiOperation({ summary: '获取登录设置' })
|
||||
@ApiResponse({ status: 200, description: '获取成功' })
|
||||
async getConfig() {
|
||||
const data = await this.loginConfigService.getConfig();
|
||||
return { code: 200, message: '获取成功', data };
|
||||
async getConfig(@Request() req: any): Promise<LoginConfig> {
|
||||
const siteId = req.user?.siteId;
|
||||
if (!siteId) {
|
||||
throw new UnauthorizedException('未授权访问:缺少 site_id');
|
||||
}
|
||||
return await this.loginConfigService.getConfig(siteId);
|
||||
}
|
||||
|
||||
@Post('config')
|
||||
@ApiOperation({ summary: '设置登录配置' })
|
||||
@ApiResponse({ status: 200, description: '设置成功' })
|
||||
async setConfig(@Body() body: LoginConfigDto) {
|
||||
const data = await this.loginConfigService.setConfig(body);
|
||||
return { code: 200, message: '设置成功', data };
|
||||
async setConfig(@Request() req: any, @Body() body: LoginConfigDto) {
|
||||
const siteId = req.user?.siteId;
|
||||
if (!siteId) {
|
||||
throw new UnauthorizedException('未授权访问:缺少 site_id');
|
||||
}
|
||||
return await this.loginConfigService.setConfig(body, siteId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { Public } from '../../../auth/decorators/public.decorator';
|
||||
import { LoginConfigApiService } from '../../services/api/LoginConfigApiService';
|
||||
import { LoginConfig } from '../../services/core/CoreLoginConfigService';
|
||||
|
||||
@Controller('api/login/config')
|
||||
export class LoginConfigApiController {
|
||||
@@ -18,7 +19,7 @@ export class LoginConfigApiController {
|
||||
*/
|
||||
@Get('info')
|
||||
@Public()
|
||||
async getInfo(@Query() query: any) {
|
||||
async getInfo(@Query() query: any): Promise<LoginConfig> {
|
||||
return this.loginConfigApiService.getInfo(query);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user