Refactor import paths to use internal/pkg/httpx/params
- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params". - Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context. - Ensured consistent usage of HTTP status responses across websocket handlers.
This commit is contained in:
@@ -3,21 +3,21 @@ package middleware
|
||||
import (
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
func AuthMiddleware(ctx iris.Context) {
|
||||
func AuthMiddleware(ctx *gin.Context) {
|
||||
if !authenticateRequest(ctx) {
|
||||
return
|
||||
}
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func authenticateRequest(ctx iris.Context) bool {
|
||||
func authenticateRequest(ctx *gin.Context) bool {
|
||||
if _, err := services.AuthService.Authenticate(ctx); err != nil {
|
||||
_ = ctx.JSON(web.JsonError(err))
|
||||
ctx.StopExecution()
|
||||
ctx.JSON(200, web.JsonError(err))
|
||||
ctx.Abort()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
func ExternalUserMiddleware(ctx iris.Context) {
|
||||
func ExternalUserMiddleware(ctx *gin.Context) {
|
||||
channel := services.ChannelService.GetEnabledChannel(ctx)
|
||||
if channel == nil {
|
||||
ctx.StopExecution()
|
||||
_ = ctx.JSON(web.JsonErrorMsg("接入渠道异常"))
|
||||
ctx.JSON(200, web.JsonErrorMsg("接入渠道异常"))
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
result, err := services.CustomerSessionService.VerifyRequest(ctx, channel)
|
||||
if err != nil {
|
||||
ctx.StopExecution()
|
||||
_ = ctx.JSON(web.JsonError(err))
|
||||
ctx.JSON(200, web.JsonError(err))
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
services.CustomerSessionService.SetRefreshHeaders(ctx, result)
|
||||
irisx.SetExternalUser(ctx, result.ExternalUser)
|
||||
httpx.SetExternalUser(ctx, result.ExternalUser)
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user