重构迁移核心数据结构到认证模块;完善中间件初始化逻辑以及 logger 记录过程
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"platform/pkg/orm"
|
||||
"platform/pkg/rds"
|
||||
"platform/pkg/u"
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
g "platform/web/globals"
|
||||
"platform/web/models"
|
||||
@@ -64,7 +65,7 @@ type ResourceInfo struct {
|
||||
|
||||
// region RemoveChannel
|
||||
|
||||
func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext, id ...int32) error {
|
||||
func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Context, id ...int32) error {
|
||||
var step = time.Now()
|
||||
var rid = ctx.Value(requestid.ConfigDefault.ContextKey).(string)
|
||||
|
||||
@@ -82,8 +83,8 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
|
||||
|
||||
// 检查权限,如果为用户操作的话,则只能删除自己的通道
|
||||
for _, channel := range channels {
|
||||
if auth.Payload.Type == PayloadUser && auth.Payload.Id != channel.UserID {
|
||||
return core.AuthForbiddenErr("无权限访问")
|
||||
if authCtx.Payload.Type == auth.PayloadUser && authCtx.Payload.Id != channel.UserID {
|
||||
return core.ForbiddenErr("无权限访问")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +239,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
|
||||
|
||||
func (s *channelService) CreateChannel(
|
||||
ctx context.Context,
|
||||
auth *AuthContext,
|
||||
authCtx *auth.Context,
|
||||
resourceId int32,
|
||||
protocol ChannelProtocol,
|
||||
authType ChannelAuthType,
|
||||
@@ -283,7 +284,7 @@ func (s *channelService) CreateChannel(
|
||||
slog.Debug("查找套餐", "rid", rid, "step", time.Since(step))
|
||||
|
||||
// 检查用户权限
|
||||
err = checkUser(auth, resource, count)
|
||||
err = checkUser(authCtx, resource, count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -302,7 +303,7 @@ func (s *channelService) CreateChannel(
|
||||
step = time.Now()
|
||||
|
||||
expiration := core.LocalDateTime(now.Add(time.Duration(resource.Live) * time.Second))
|
||||
_addr, channels, err := assignPort(q, edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
||||
_addr, channels, err := assignPort(q, edgeAssigns, authCtx.Payload.Id, protocol, authType, expiration, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -356,11 +357,11 @@ func (s *channelService) CreateChannel(
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
func checkUser(auth *AuthContext, resource *ResourceInfo, count int) error {
|
||||
func checkUser(authCtx *auth.Context, resource *ResourceInfo, count int) error {
|
||||
|
||||
// 检查使用人
|
||||
if auth.Payload.Type == PayloadUser && auth.Payload.Id != resource.UserId {
|
||||
return core.AuthForbiddenErr("无权限访问")
|
||||
if authCtx.Payload.Type == auth.PayloadUser && authCtx.Payload.Id != resource.UserId {
|
||||
return core.ForbiddenErr("无权限访问")
|
||||
}
|
||||
|
||||
// 检查套餐状态
|
||||
|
||||
Reference in New Issue
Block a user