This commit is contained in:
孟帅
2023-05-12 16:20:22 +08:00
parent f30fd885be
commit 9198a53584
52 changed files with 982 additions and 834 deletions

View File

@@ -3,7 +3,6 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package middleware
import (
@@ -13,34 +12,30 @@ import (
"github.com/gogf/gf/v2/text/gstr"
"hotgo/internal/consts"
"hotgo/internal/library/response"
"hotgo/utility/auth"
)
// ApiAuth API鉴权中间件
func (s *sMiddleware) ApiAuth(r *ghttp.Request) {
var ctx = r.Context()
var (
ctx = r.Context()
prefix = g.Cfg().MustGet(ctx, "router.api.prefix", "/api").String()
path = gstr.Replace(r.URL.Path, prefix, "", 1)
)
// 替换掉模块前缀
routerPrefix := g.Cfg().MustGet(ctx, "router.api.prefix", "/api")
path := gstr.Replace(r.URL.Path, routerPrefix.String(), "", 1)
/// 不需要验证登录的路由地址
if auth.IsExceptLogin(ctx, path) {
// 不需要验证登录的路由地址
if isExceptLogin(ctx, consts.AppApi, path) {
r.Middleware.Next()
return
}
if err := inspectAuth(r, consts.AppAdmin); err != nil {
// 将用户信息传递到上下文中
if err := deliverUserContext(r); err != nil {
response.JsonExit(r, gcode.CodeNotAuthorized.Code(), err.Error())
return
}
//// 验证路由访问权限
//verify := service.AdminRole().Verify(ctx, path, r.Method)
//if !verify {
// response.JsonExit(r, consts.CodeSecurityReason, "你没有访问权限!")
// return
//}
// 验证路由访问权限
// ...
r.Middleware.Next()
}