Skip to content

Commit

Permalink
Update clamis.go (#1450)
Browse files Browse the repository at this point in the history
添加了GetUserName方法
  • Loading branch information
JusticeGL committed Jun 9, 2023
1 parent eb86bc5 commit ef4c8a7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/utils/clamis.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ func GetUserInfo(c *gin.Context) *systemReq.CustomClaims {
return waitUse
}
}

// GetUserName 从Gin的Context中获取从jwt解析出来的用户名
func GetUserName(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
if cl, err := GetClaims(c); err != nil {
return ""
} else {
return cl.Username
}
} else {
waitUse := claims.(*systemReq.CustomClaims)
return waitUse.Username
}
}

0 comments on commit ef4c8a7

Please sign in to comment.