sysmgr-nest/src/auth/auth.controller.ts
liuyun 7340658305 feat: enforce RBAC, audit/login logging, and seed script
收口 Phase 0 三处「声明未生效」:
- 三级鉴权落地:权限集存 Redis(key 前缀隔离多项目),@RequirePermissions 挂到全部受控接口,super_admin 角色绕过权限码与 data_scope
- 审计/登录日志自动落库:@AuditLog 装饰器 + 拦截器异步写入(写操作+登录登出),登录成功/失败均记 login_log(脱敏)
- seed 脚本:一键初始化租户 touyun/用户 touyun/超管 super_admin/全量资源树(48 资源全量授权)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 23:19:41 +08:00

29 lines
773 B
TypeScript

import { Body, Controller, Post, Req } from '@nestjs/common';
import type { Request } from 'express';
import { AuthService } from './auth.service.js';
import { LoginDto, RefreshDto } from './dto.js';
import { Public } from './decorators.js';
@Controller('auth')
export class AuthController {
constructor(private readonly auth: AuthService) {}
@Public()
@Post('login')
login(@Body() dto: LoginDto, @Req() req: Request) {
return this.auth.login(dto, req.ip, req.headers['user-agent']);
}
@Public()
@Post('refresh')
refresh(@Body() dto: RefreshDto) {
return this.auth.refresh(dto);
}
@Public()
@Post('logout')
logout(@Body() dto: RefreshDto, @Req() req: Request) {
return this.auth.logout(dto, req.ip, req.headers['user-agent']);
}
}