Browse Source

从头部获取用户信息的方法整理 增加不鉴权模式下的信息获取

main
蒋吉兆 3 years ago
parent
commit
688624299e
  1. 2
      server/middleware/casbin_rbac.go
  2. 4
      server/middleware/email.go
  3. 2
      server/middleware/operation.go

2
server/middleware/casbin_rbac.go

@ -13,7 +13,7 @@ var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService
// 拦截器 // 拦截器
func CasbinHandler() gin.HandlerFunc { func CasbinHandler() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
waitUse := utils.GetClaims(c)
waitUse, _ := utils.GetClaims(c)
// 获取请求的URI // 获取请求的URI
obj := c.Request.URL.RequestURI() obj := c.Request.URL.RequestURI()
// 获取请求方法 // 获取请求方法

4
server/middleware/email.go

@ -19,8 +19,8 @@ var userService = service.ServiceGroupApp.SystemServiceGroup.UserService
func ErrorToEmail() gin.HandlerFunc { func ErrorToEmail() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
var username string var username string
claims := utils2.GetClaims(c)
if claims.Username !="" {
claims, _ := utils2.GetClaims(c)
if claims.Username != "" {
username = claims.Username username = claims.Username
} else { } else {
id, _ := strconv.Atoi(c.Request.Header.Get("x-user-id")) id, _ := strconv.Atoi(c.Request.Header.Get("x-user-id"))

2
server/middleware/operation.go

@ -30,7 +30,7 @@ func OperationRecord() gin.HandlerFunc {
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
} }
} }
claims := utils.GetClaims(c)
claims, _ := utils.GetClaims(c)
if claims.ID != 0 { if claims.ID != 0 {
userId = int(claims.ID) userId = int(claims.ID)
} else { } else {

Loading…
Cancel
Save