39 lines
813 B
Go
39 lines
813 B
Go
package middleware
|
|
|
|
import (
|
|
"likedream-goframe/internal/common/cst"
|
|
"likedream-goframe/internal/utils"
|
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
)
|
|
|
|
func PermissionHandler(r *ghttp.Request) {
|
|
handler := r.GetServeHandler()
|
|
if !utils.IsController(handler) {
|
|
r.Middleware.Next()
|
|
return
|
|
}
|
|
permission := handler.GetMetaTag("permission")
|
|
if permission == "" {
|
|
r.Middleware.Next()
|
|
return
|
|
}
|
|
authTag := handler.GetMetaTag("auth")
|
|
if authTag == "false" {
|
|
r.Middleware.Next()
|
|
return
|
|
}
|
|
value := r.GetCtx().Value(cst.CtxPermissionList)
|
|
permissionList := value.([]string)
|
|
if utils.IsAdmin(permissionList) {
|
|
r.Middleware.Next()
|
|
return
|
|
}
|
|
if utils.IsInPermission(permission, permissionList) {
|
|
r.Middleware.Next()
|
|
return
|
|
}
|
|
r.Response.ClearBuffer()
|
|
r.Response.WriteJson(utils.PermissionDenied())
|
|
}
|