hi-server/internal/handler/auth/checkCodeLegacyHandler.go
shanshanzhong a01570b59d
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 8m21s
fix gitea workflow path and runner label
2026-03-04 06:33:14 -08:00

51 lines
1.5 KiB
Go

package auth
import (
"github.com/gin-gonic/gin"
commonLogic "github.com/perfect-panel/server/internal/logic/common"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/constant"
"github.com/perfect-panel/server/pkg/result"
)
// Check legacy verification code
func CheckCodeLegacyHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.LegacyCheckVerificationCodeRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
normalizedReq, legacyType3Mapped, err := commonLogic.NormalizeLegacyCheckVerificationCodeRequest(&req)
if err != nil {
result.ParamErrorResult(c, err)
return
}
l := commonLogic.NewCheckVerificationCodeLogic(c.Request.Context(), svcCtx)
useLatest := false
if value, ok := c.Request.Context().Value(constant.CtxKeyAPIVersionUseLatest).(bool); ok {
useLatest = value
}
resp, err := l.CheckVerificationCodeWithBehavior(normalizedReq, commonLogic.VerifyCodeCheckBehavior{
Source: "legacy",
Consume: useLatest,
LegacyType3Mapped: legacyType3Mapped,
AllowSceneFallback: constant.ParseVerifyType(normalizedReq.Type) != constant.DeleteAccount,
})
legacyResp := &types.LegacyCheckVerificationCodeResponse{}
if resp != nil {
legacyResp.Status = resp.Status
legacyResp.Exist = resp.Status
}
result.HttpResult(c, legacyResp, err)
}
}