From 16b4f0a0be91a57f4ddf33d2b48d91e2a924dd15 Mon Sep 17 00:00:00 2001 From: skyle1995 Date: Mon, 30 Mar 2026 00:40:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?cookie=20=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/admin/captcha.go | 1 - utils/cookie.go | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/controllers/admin/captcha.go b/controllers/admin/captcha.go index 028630f..b055a99 100644 --- a/controllers/admin/captcha.go +++ b/controllers/admin/captcha.go @@ -104,7 +104,6 @@ func VerifyCaptcha(c *gin.Context, captchaValue string) bool { logrus.WithError(err).Warn("验证码验证失败:无法从Cookie获取captcha_id") return false } - logrus.Infof("VerifyCaptcha: received captchaId=%s, captchaValue=%s", captchaId, captchaValue) // 先尝试原始值验证 if store.Verify(captchaId, captchaValue, false) { diff --git a/utils/cookie.go b/utils/cookie.go index 329ad10..a3b00b7 100644 --- a/utils/cookie.go +++ b/utils/cookie.go @@ -2,6 +2,7 @@ package utils import ( "net/http" + "strings" "time" ) @@ -9,6 +10,20 @@ import ( // Cookie创建函数 // ============================================================================ +// FormatCookies formats a slice of cookies into a string suitable for HTTP headers +func FormatCookies(cookies []*http.Cookie) string { + var b strings.Builder + for i, c := range cookies { + if i > 0 { + b.WriteString("; ") + } + b.WriteString(c.Name) + b.WriteRune('=') + b.WriteString(c.Value) + } + return b.String() +} + // CreateSecureCookie 创建安全的Cookie // name: Cookie名称 // value: Cookie值