2026-04-09 10:01:23 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cs-agent/internal/pkg/irisx"
|
2026-04-28 10:15:15 +08:00
|
|
|
"cs-agent/internal/services"
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
|
"github.com/mlogclub/simple/web"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-28 11:10:47 +08:00
|
|
|
func ExternalUserMiddleware(ctx iris.Context) {
|
2026-04-28 10:15:15 +08:00
|
|
|
channel := services.ChannelService.GetEnabledChannel(ctx)
|
2026-04-28 10:40:53 +08:00
|
|
|
if channel == nil {
|
|
|
|
|
ctx.StopExecution()
|
|
|
|
|
_ = ctx.JSON(web.JsonErrorMsg("接入渠道异常"))
|
|
|
|
|
return
|
2026-04-28 10:15:15 +08:00
|
|
|
}
|
2026-04-28 19:56:27 +08:00
|
|
|
result, err := services.CustomerSessionService.VerifyRequest(ctx, channel)
|
2026-04-09 10:01:23 +08:00
|
|
|
if err != nil {
|
|
|
|
|
ctx.StopExecution()
|
|
|
|
|
_ = ctx.JSON(web.JsonError(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-28 19:56:27 +08:00
|
|
|
services.CustomerSessionService.SetRefreshHeaders(ctx, result)
|
|
|
|
|
irisx.SetExternalUser(ctx, result.ExternalUser)
|
2026-04-09 10:01:23 +08:00
|
|
|
ctx.Next()
|
|
|
|
|
}
|