2026-04-09 10:01:23 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-23 22:10:20 +08:00
|
|
|
"cs-agent/internal/pkg/httpx"
|
2026-04-28 10:15:15 +08:00
|
|
|
"cs-agent/internal/services"
|
2026-04-09 10:01:23 +08:00
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2026-04-09 10:01:23 +08:00
|
|
|
"github.com/mlogclub/simple/web"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
func ExternalUserMiddleware(ctx *gin.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 {
|
2026-05-23 22:10:20 +08:00
|
|
|
ctx.JSON(200, web.JsonErrorMsg("接入渠道异常"))
|
|
|
|
|
ctx.Abort()
|
2026-04-28 10:40:53 +08:00
|
|
|
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 {
|
2026-05-23 22:10:20 +08:00
|
|
|
ctx.JSON(200, web.JsonError(err))
|
|
|
|
|
ctx.Abort()
|
2026-04-09 10:01:23 +08:00
|
|
|
return
|
|
|
|
|
}
|
2026-04-28 19:56:27 +08:00
|
|
|
services.CustomerSessionService.SetRefreshHeaders(ctx, result)
|
2026-05-23 22:10:20 +08:00
|
|
|
httpx.SetExternalUser(ctx, result.ExternalUser)
|
2026-04-09 10:01:23 +08:00
|
|
|
ctx.Next()
|
|
|
|
|
}
|