This commit is contained in:
XOF
2025-11-20 12:24:05 +08:00
commit f28bdc751f
164 changed files with 64248 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// Filename: internal/webhandlers/auth_handler.go (最终现代化改造版)
package webhandlers
import (
"gemini-balancer/internal/middleware"
"gemini-balancer/internal/service" // [核心改造] 依赖service层
"net/http"
"github.com/gin-gonic/gin"
)
// WebAuthHandler [核心改造] 依赖关系净化注入SecurityService
type WebAuthHandler struct {
securityService *service.SecurityService
}
// NewWebAuthHandler [核心改造] 构造函数更新
func NewWebAuthHandler(securityService *service.SecurityService) *WebAuthHandler {
return &WebAuthHandler{
securityService: securityService,
}
}
// ShowLoginPage 保持不变
func (h *WebAuthHandler) ShowLoginPage(c *gin.Context) {
errMsg := c.Query("error")
from := c.Query("from") // 可以从登录失败的页面返回
c.HTML(http.StatusOK, "auth.html", gin.H{
"error": errMsg,
"from": from,
})
}
// HandleLogin [核心改造] 认证逻辑完全委托给SecurityService
func (h *WebAuthHandler) HandleLogin(c *gin.Context) {
c.Redirect(http.StatusFound, "/login?error=DEPRECATED_LOGIN_METHOD")
}
// HandleLogout 保持不变
func (h *WebAuthHandler) HandleLogout(c *gin.Context) {
middleware.ClearAdminSessionCookie(c)
c.Redirect(http.StatusFound, "/login")
}