123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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 ""
- }
|