| | |
| | | return claims, err |
| | | } |
| | | |
| | | // GetUserID 从Gin的Context中获取从jwt解析出来的用户ID |
| | | func GetUserID(c *gin.Context) string { |
| | | if claims, exists := c.Get("claims"); !exists { |
| | | if cl, err := GetClaims(c); err != nil { |
| | | return "" |
| | | } else { |
| | | return cl.UserId |
| | | } |
| | | } else { |
| | | func GetUserID(c *gin.Context) int { |
| | | if claims, exists := c.Get("claims"); exists { |
| | | waitUse := claims.(*request.CustomClaims) |
| | | return waitUse.UserId |
| | | return waitUse.CrmUserId |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | // GetUserInfo 从Gin的Context中获取从jwt解析出来的用户信息 |
| | | func GetUserInfo(c *gin.Context) *request.CustomClaims { |
| | | if claims, exists := c.Get("claims"); !exists { |
| | | if cl, err := GetClaims(c); err != nil { |
| | | return nil |
| | | } else { |
| | | return cl |
| | | } |
| | | } else { |
| | | if claims, exists := c.Get("claims"); exists { |
| | | waitUse := claims.(*request.CustomClaims) |
| | | return waitUse |
| | | } |
| | | return nil |
| | | } |