fix: 设计原则审查修复 — DIP/ISP, LoD, DRY, OCP, URL, 301缓存
- P0 DIP+ISP: 全链路注入接口,消除零接口紧耦合 - P0 URL: auth 301→302,修复登出后浏览器缓存陷阱 - P1 DRY: JWT 认证逻辑收敛至 TokenService+中间件 - P2 DRY: 前后端角色/状态映射统一为 model 常量 - P2 LoD: 新增 SettingsController,router 不再跨层调 repo - P2 URL: settings ?tab= → /settings/:tab 伪静态 - P3 OCP: 角色权限 map 化,告别硬编码 switch
This commit is contained in:
@ -27,6 +27,7 @@ func Setup(r *gin.Engine, db *gorm.DB, cfg *config.Config) {
|
||||
authService := service.NewAuthService(userRepo, tokenSvc, cfg)
|
||||
rateLimiter := middleware.NewRateLimiter()
|
||||
authCtrl := controller.NewAuthController(authService, tokenSvc, rateLimiter, cfg)
|
||||
settingsCtrl := controller.NewSettingsController(authService)
|
||||
|
||||
authMdw := middleware.NewAuthMiddleware(cfg, userRepo)
|
||||
|
||||
@ -50,6 +51,12 @@ func Setup(r *gin.Engine, db *gorm.DB, cfg *config.Config) {
|
||||
"ExtraCSS": "/static/css/home.css",
|
||||
}))
|
||||
})
|
||||
|
||||
// 个人设置页(需登录,/:tab 为伪静态子页面)
|
||||
pages.GET("/settings", func(c *gin.Context) {
|
||||
c.Redirect(http.StatusFound, "/settings/profile")
|
||||
})
|
||||
pages.GET("/settings/:tab", settingsCtrl.SettingsPage)
|
||||
}
|
||||
|
||||
// 认证页面(已登录自动跳走)
|
||||
@ -67,7 +74,7 @@ func Setup(r *gin.Engine, db *gorm.DB, cfg *config.Config) {
|
||||
|
||||
// --- 管理后台 SSR 页面(认证失败 302 跳首页) ---
|
||||
adminPages := r.Group("/admin")
|
||||
adminPages.Use(middleware.AdminAuth(cfg, userRepo))
|
||||
adminPages.Use(authMdw.AdminAuth())
|
||||
adminPages.Use(middleware.RequirePageRole(model.RoleModerator))
|
||||
adminPages.Use(middleware.CSRF(cfg))
|
||||
adminPages.Use(func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user