增加多角色功能和角色切换功能
调整前端获取用户信息方式
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"gin-vue-admin/global"
|
||||
systemReq "gin-vue-admin/model/system/request"
|
||||
"github.com/gin-gonic/gin"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户ID
|
||||
@@ -18,13 +19,13 @@ func GetUserID(c *gin.Context) uint {
|
||||
}
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户UUID
|
||||
func GetUserUuid(c *gin.Context) string {
|
||||
func GetUserUuid(c *gin.Context) uuid.UUID {
|
||||
if claims, exists := c.Get("claims"); !exists {
|
||||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
||||
return ""
|
||||
return uuid.UUID{}
|
||||
} else {
|
||||
waitUse := claims.(*systemReq.CustomClaims)
|
||||
return waitUse.UUID.String()
|
||||
return waitUse.UUID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,3 +39,14 @@ func GetUserAuthorityId(c *gin.Context) string {
|
||||
return waitUse.AuthorityId
|
||||
}
|
||||
}
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户角色id
|
||||
func GetUserInfo(c *gin.Context) *systemReq.CustomClaims {
|
||||
if claims, exists := c.Get("claims"); !exists {
|
||||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!")
|
||||
return nil
|
||||
} else {
|
||||
waitUse := claims.(*systemReq.CustomClaims)
|
||||
return waitUse
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user