From 8418dbe7c46392becc50086ef1445e159ee6acf1 Mon Sep 17 00:00:00 2001 From: "1808837298@qq.com" <1808837298@qq.com> Date: Mon, 10 Feb 2025 20:52:33 +0800 Subject: [PATCH] fix: replace context-based user ID with session-based retrieval #741 - Update user and wechat controllers to use sessions for user ID - Modify ID retrieval to use `session.Get("id")` instead of `c.GetInt("id")` - Cast session ID to int when creating user object --- controller/user.go | 5 +++-- controller/wechat.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/controller/user.go b/controller/user.go index 9e1361f4..7146f00e 100644 --- a/controller/user.go +++ b/controller/user.go @@ -846,9 +846,10 @@ func EmailBind(c *gin.Context) { }) return } - id := c.GetInt("id") + session := sessions.Default(c) + id := session.Get("id") user := model.User{ - Id: id, + Id: id.(int), } err := user.FillUserById() if err != nil { diff --git a/controller/wechat.go b/controller/wechat.go index 7f048c90..9b5f2070 100644 --- a/controller/wechat.go +++ b/controller/wechat.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" "net/http" "one-api/common" @@ -142,9 +143,10 @@ func WeChatBind(c *gin.Context) { }) return } - id := c.GetInt("id") + session := sessions.Default(c) + id := session.Get("id") user := model.User{ - Id: id, + Id: id.(int), } err = user.FillUserById() if err != nil {