package middleware
|
|
|
|
import (
|
|
"LAPP_LF_MOM_BACKEND/conf"
|
|
"LAPP_LF_MOM_BACKEND/utils"
|
|
"LAPP_LF_MOM_BACKEND/web/middleware/jwts"
|
|
"github.com/kataras/iris/v12"
|
|
"strings"
|
|
)
|
|
|
|
type Middleware struct {
|
|
}
|
|
|
|
func ServeHTTP(ctx iris.Context) {
|
|
path := ctx.Path()
|
|
// 过滤静态资源、login接口、首页等...不需要验证
|
|
if checkURL(path) || strings.Contains(path, "/public") {
|
|
ctx.Next()
|
|
return
|
|
}
|
|
// jwt token拦截
|
|
if !jwts.Serve(ctx) {
|
|
return
|
|
}
|
|
|
|
// 系统菜单不进行权限拦截
|
|
publicRutes := conf.AppConfig.PublicRute
|
|
res := utils.IsContain(publicRutes,path)
|
|
if !res {
|
|
// casbin权限拦截
|
|
//ok := casbins.CheckPermissions(ctx)
|
|
//if !ok {
|
|
// return
|
|
//}
|
|
}
|
|
//if !strings.Contains(path, "/sysMenu") {
|
|
// // casbin权限拦截
|
|
// ok := casbins.CheckPermissions(ctx)
|
|
// if !ok {
|
|
// return
|
|
// }
|
|
//}
|
|
|
|
// Pass to real API
|
|
ctx.Next()
|
|
}
|
|
|
|
/**
|
|
return
|
|
true:则跳过不需验证,如登录接口等...
|
|
false:需要进一步验证
|
|
*/
|
|
func checkURL(reqPath string) bool {
|
|
//过滤
|
|
for _, v := range conf.AppConfig.Other.IgnoreURLs {
|
|
if reqPath == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|