Files
gemini-banlancer/internal/webhandlers/auth_handler.go
2025-11-20 12:24:05 +08:00

44 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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")
}