Modify jwt middleware logic

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-02 12:36:07 +08:00
parent 3d685b5a86
commit cbec9bf2b3
7 changed files with 85 additions and 50 deletions

View File

@@ -13,16 +13,22 @@ func Update(c *gin.Context) {
// New user model
user := new(data.User)
userId, ok := c.Get("user_id")
userIdOrig, ok := c.Get("user_id")
if !ok {
c.JSON(403, gin.H{
"status": "can not found user id",
})
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
c.JSON(500, gin.H{
"status": "failed to parse uuid",
})
}
// Get user info
user.GetByUserId(userId.(uuid.UUID))
user.GetByUserId(userId)
// Reject permission 0 user
if user.PermissionLevel == 0 {
@@ -38,7 +44,7 @@ func Update(c *gin.Context) {
user.Subtitle = ReqInfo.Subtitle
// Update user info
user.UpdateByUserID(userId.(uuid.UUID))
user.UpdateByUserID(userId)
c.JSON(200, gin.H{
"status": "success",