refactor(auth): move captcha verification from handler to logic layer

- Remove duplicate captcha verification from user login handler
- Remove duplicate captcha verification from user register handler
- Remove duplicate captcha verification from password reset handler
- Remove duplicate captcha verification from phone login handler
- Remove duplicate captcha verification from phone register handler
- Update phone reset password handler structure
- Improve separation of concerns between handler and logic layers
- Handlers now only handle HTTP request/response, logic handles business rules
This commit is contained in:
EUForest
2026-03-09 22:56:07 +08:00
parent fae77a8954
commit 3ca471f58c
6 changed files with 43 additions and 89 deletions
+2 -16
View File
@@ -1,16 +1,11 @@
package auth
import (
"time"
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/auth"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
"github.com/perfect-panel/server/pkg/turnstile"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
// Reset password
@@ -25,17 +20,8 @@ func ResetPasswordHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
}
// get client ip
req.IP = c.ClientIP()
if svcCtx.Config.Verify.ResetPasswordVerify {
verifyTurns := turnstile.New(turnstile.Config{
Secret: svcCtx.Config.Verify.TurnstileSecret,
Timeout: 3 * time.Second,
})
if verify, err := verifyTurns.Verify(c, req.CfToken, req.IP); err != nil || !verify {
err = errors.Wrapf(xerr.NewErrCode(xerr.TooManyRequests), "error: %v, verify: %v", err, verify)
result.HttpResult(c, nil, err)
return
}
}
req.UserAgent = c.Request.UserAgent()
l := auth.NewResetPasswordLogic(c.Request.Context(), svcCtx)
resp, err := l.ResetPassword(&req)
result.HttpResult(c, resp, err)