mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-26 03:46:38 +08:00
Update github.go
在该函数中,有一行注释显示了一个严重错误:github.go:203-204GitHubBind 错误在第 204 行,代码从会话中检索用户 ID,但有一个带注释的第 203 行显示了原始(有问题的)实现:github.go:203// id := c.GetInt("id") // critical bug! 问题 原始的 bug 代码会尝试从 Gin 上下文中获取用户 ID,但这将失败,因为:c.GetInt("id") 用户 ID 不会在此端点的 Gin 上下文中自动设置 这可能会返回 0 或在尝试绑定 GitHub 帐户时导致 panic 然后,该函数将尝试更新 ID 为 0 的用户,而该 ID 不存在
This commit is contained in:
parent
5f1c5945f8
commit
a2d95f62c4
@ -198,10 +198,26 @@ func GitHubBind(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
session := sessions.Default(c)
|
||||
id := session.Get("id")
|
||||
// id := c.GetInt("id") // critical bug!
|
||||
user.Id = id.(int)
|
||||
func GitHubBind(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
idInterface := session.Get("id")
|
||||
if idInterface == nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"success": false,
|
||||
"message": "用户未登录",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
id, ok := idInterface.(int)
|
||||
if !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"success": false,
|
||||
"message": "用户ID类型错误",
|
||||
})
|
||||
return
|
||||
}
|
||||
user.Id = id
|
||||
err = user.FillUserById()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
Loading…
Reference in New Issue
Block a user