- 安全:移除 CSP 中 esm.sh/cdnjs.cloudflare.com,highlight.js 主题已本地化 73 个文件 - 安全:StatusBanned 分支补 dummy hash 防时序攻击 - 安全:手写 constantTimeEq 替换为 crypto/subtle.ConstantTimeCompare - Bug:锁定操作消息已删除→已锁定 - YAGNI:删除 12 个空预留模板目录 - KISS:删除 common.CheckPassword 薄封装,统一用 bcrypt 调用 - KISS:删除 tokenCtrl 别名字段,api.go 统一用 authCtrl - RateLimiter:check()+recordFail 闭包模式重构为 try() 原子操作,消除竞态 - RateLimiter:新增 ClearIP() 方法,注册成功时清除 IP 计数 - 文档:修正 audit_service.go 注释编号跳跃(3→5→4) - 文档:修正 deps_core.go 过清理→过期清理
64 lines
2.5 KiB
Go
64 lines
2.5 KiB
Go
package controller
|
||
|
||
import (
|
||
"metazone.cc/metalab/internal/middleware"
|
||
"metazone.cc/metalab/internal/model"
|
||
"metazone.cc/metalab/internal/service"
|
||
"metazone.cc/metalab/internal/session"
|
||
)
|
||
|
||
// authUseCase AuthController 对 AuthService 的最小依赖(ISP:5 个方法)
|
||
// 注意:Login/Register/ConfirmRestore 不再返回 JWT,session 由 controller 通过 SessionManager 创建
|
||
type authUseCase interface {
|
||
Register(req model.RegisterRequest, regIP string) (*model.User, error)
|
||
Login(req model.LoginRequest, loginIP string) (*model.User, error)
|
||
ConfirmRestore(req model.LoginRequest, loginIP string) (*model.User, error)
|
||
CheckEmail(email string) (bool, error)
|
||
IsRegistrationEnabled() bool
|
||
}
|
||
|
||
// rateLimiter AuthController 对 RateLimiter 的最小依赖(ISP:4 个方法)
|
||
type rateLimiter interface {
|
||
AllowAccount(email string) middleware.RateLimitResult
|
||
AllowIP(ip string) middleware.RateLimitResult
|
||
Clear(email, ip string)
|
||
ClearIP(ipKey string)
|
||
}
|
||
|
||
// postUseCase PostController 对 PostService 的最小依赖(ISP:7 个方法)
|
||
type postUseCase interface {
|
||
Create(userID uint, title, body string) (*model.Post, error)
|
||
GetByID(id uint) (*model.Post, error)
|
||
List(keyword string, page, pageSize int) ([]model.Post, int64, error)
|
||
Update(postID uint, title, body string) error
|
||
Delete(postID uint) error
|
||
SubmitForAudit(postID uint) error
|
||
IsPostAccessible(userID uint, role string, postUserID uint) bool
|
||
}
|
||
|
||
// studioUseCase StudioController 对 PostService 的最小依赖(ISP:8 个方法)
|
||
type studioUseCase interface {
|
||
Create(userID uint, title, body string) (*model.Post, error)
|
||
GetByID(id uint) (*model.Post, error)
|
||
Update(postID uint, title, body string) error
|
||
Delete(postID uint) error
|
||
SubmitForAudit(postID uint) error
|
||
ListByUser(userID uint, status string, page, pageSize int) ([]model.Post, int64, error)
|
||
GetOverview(userID uint) (*service.StudioOverview, error)
|
||
IsPostAccessible(userID uint, role string, postUserID uint) bool
|
||
}
|
||
|
||
// spaceUseCase SpaceController 对 SpaceService 的最小依赖(ISP:2 个方法)
|
||
type spaceUseCase interface {
|
||
GetSpaceUser(uid uint) (*model.User, error)
|
||
GetPostsByUser(uid uint, page, pageSize int) ([]model.Post, int64, error)
|
||
}
|
||
|
||
// sessionManager 登录管理对会话管理的最小依赖(ISP:4 个方法)
|
||
type sessionManager interface {
|
||
ListByUID(uid uint) ([]*session.Session, error)
|
||
Destroy(sid string) error
|
||
DestroyOtherByUID(uid uint, currentSID string) error
|
||
UpdateRemark(sid string, uid uint, remark string) error
|
||
}
|