feat: 若无接口权限,提示没有那个接口权限。
This commit is contained in:
parent
648cce1beb
commit
a2e03bbf06
@ -1,11 +1,14 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"ferry/global/orm"
|
||||
"ferry/models/system"
|
||||
mycasbin "ferry/pkg/casbin"
|
||||
"ferry/pkg/jwtauth"
|
||||
_ "ferry/pkg/jwtauth"
|
||||
"ferry/pkg/logger"
|
||||
"ferry/tools"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -14,6 +17,8 @@ import (
|
||||
//权限检查中间件
|
||||
func AuthCheckRole() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var menuValue system.Menu
|
||||
|
||||
data, _ := c.Get("JWT_PAYLOAD")
|
||||
v := data.(jwtauth.MapClaims)
|
||||
e, err := mycasbin.Casbin()
|
||||
@ -24,12 +29,17 @@ func AuthCheckRole() gin.HandlerFunc {
|
||||
|
||||
tools.HasError(err, "", 500)
|
||||
|
||||
err = orm.Eloquent.Model(&menuValue).
|
||||
Where("path = ? and action = ?", c.Request.URL.Path, c.Request.Method).
|
||||
Find(&menuValue).Error
|
||||
tools.HasError(err, "", 500)
|
||||
|
||||
if res {
|
||||
c.Next()
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 403,
|
||||
"msg": "对不起,您没有该接口访问权限,请联系管理员",
|
||||
"msg": fmt.Sprintf("对不起,您没有 <%v> 访问权限,请联系管理员", menuValue.Title),
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user