From c97e2875b4a9c51acade27723a89baacb5da0575 Mon Sep 17 00:00:00 2001 From: GuoRuqiang <61670021+guoruqiang@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:12:59 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E5=86=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E5=88=9D=E5=A7=8B=E4=BB=A4=E7=89=8C?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/user.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/controller/user.go b/controller/user.go index 6faec2b..7a3edf4 100644 --- a/controller/user.go +++ b/controller/user.go @@ -186,6 +186,37 @@ func Register(c *gin.Context) { }) return } + + // 获取插入后的用户ID + var insertedUser model.User + if err := model.DB.Where("username = ?", cleanUser.Username).First(&insertedUser).Error; err != nil { + c.JSON(http.StatusOK, gin.H{ + "success": false, + "message": "用户注册失败或用户ID获取失败", + }) + return + } + // 生成默认令牌 + // tokenName := cleanUser.Username + "的初始令牌" + token := model.Token{ + UserId: insertedUser.Id, // 使用插入后的用户ID + Name: cleanUser.Username + "的初始令牌", + Key: common.GenerateKey(), + CreatedTime: common.GetTimestamp(), + AccessedTime: common.GetTimestamp(), + ExpiredTime: -1, // 永不过期 + RemainQuota: 500000, // 示例额度 + UnlimitedQuota: true, + ModelLimitsEnabled: false, + } + if err := token.Insert(); err != nil { + c.JSON(http.StatusOK, gin.H{ + "success": false, + "message": "创建默认令牌失败", + }) + return + } + c.JSON(http.StatusOK, gin.H{ "success": true, "message": "",