Skip to content

Commit

Permalink
fix: 初始令牌
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Sep 17, 2024
1 parent 131453d commit 9032b5c
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func Register(c *gin.Context) {
})
return
}

// 获取插入后的用户ID
var insertedUser model.User
if err := model.DB.Where("username = ?", cleanUser.Username).First(&insertedUser).Error; err != nil {
Expand All @@ -199,23 +199,15 @@ func Register(c *gin.Context) {
}
// 生成默认令牌
if constant.GenerateDefaultToken {
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
}
// 生成默认令牌
token := model.Token{
UserId: insertedUser.Id, // 使用插入后的用户ID
Name: cleanUser.Username + "的初始令牌",
Name: cleanUser.Username + "的初始令牌",
Key: common.GenerateKey(),
CreatedTime: common.GetTimestamp(),
AccessedTime: common.GetTimestamp(),
ExpiredTime: -1, // 永不过期
RemainQuota: 500000, // 示例额度
ExpiredTime: -1, // 永不过期
RemainQuota: 500000, // 示例额度
UnlimitedQuota: true,
ModelLimitsEnabled: false,
}
Expand Down

0 comments on commit 9032b5c

Please sign in to comment.