package user import ( "fmt" "github.com/gin-gonic/gin" "gogs.baozhida.cn/zoie/OAuth-core/pkg" jwt "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth" ) func ExtractClaims(c *gin.Context) jwt.MapClaims { claims, exists := c.Get(jwt.JwtPayloadKey) if !exists { return make(jwt.MapClaims) } return claims.(jwt.MapClaims) } func Get(c *gin.Context, key string) interface{} { data := ExtractClaims(c) if data[key] != nil { return data[key] } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " Get 缺少 " + key) return nil } func GetUUID(c *gin.Context) string { data := ExtractClaims(c) if data["uuid"] != nil { return (data["uuid"]).(string) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUUID 缺少 uuid") return "" } func GetUserId(c *gin.Context) int { data := ExtractClaims(c) if data["identity"] != nil { return int((data["identity"]).(float64)) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少 identity") return 0 } func GetUserIdStr(c *gin.Context) string { data := ExtractClaims(c) if data["identity"] != nil { return pkg.Int64ToString(int64((data["identity"]).(float64))) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserIdStr 缺少 identity") return "" } func GetUserName(c *gin.Context) string { data := ExtractClaims(c) if data["username"] != nil { return (data["username"]).(string) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserName 缺少 username") return "" } func GetRoleName(c *gin.Context) string { data := ExtractClaims(c) if data["roleName"] != nil { return (data["roleName"]).(string) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleName 缺少 roleName") return "" } func GetRoleKey(c *gin.Context) string { data := ExtractClaims(c) if data["roleKey"] != nil { return (data["roleKey"]).(string) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleKey 缺少 roleKey") return "" } func GetRoleId(c *gin.Context) int { data := ExtractClaims(c) if data["roleId"] != nil { i := int((data["roleId"]).(float64)) return i } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少 roleId") return 0 } func GetDataScope(c *gin.Context) int { data := ExtractClaims(c) if data["dataScope"] != nil { i := int((data["dataScope"]).(float64)) return i } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDataScope 缺少 dataScope") return 0 } func GetDeptId(c *gin.Context) int { data := ExtractClaims(c) if data["deptId"] != nil { return int((data["deptId"]).(float64)) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptId 缺少 deptId") return 0 } func GetDeptName(c *gin.Context) string { data := ExtractClaims(c) if data["deptName"] != nil { return (data["deptName"]).(string) } fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptName 缺少 deptName") return "" }