hi-server/internal/handler/public/user/deleteAccountHandler.go
shanshanzhong e1616765c7
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m51s
refactor(auth): 移除设备登录逻辑中的错误处理并简化代码
refactor(user): 修改删除账号处理器的邮箱验证逻辑
2025-10-31 02:14:28 -07:00

53 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package user
import (
"context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/public/user"
"github.com/perfect-panel/server/internal/svc"
)
// DeleteAccountHandler 注销账号处理器
// 根据当前token删除所有关联设备然后根据各自设备ID重新新建账号
// 新增:需携带邮箱验证码,验证通过后执行注销
type deleteAccountReq struct {
Email string `json:"email" binding:"required,email"` // 用户邮箱
Code string `json:"code" binding:"required"` // 邮箱验证码
}
func DeleteAccountHandler(serverCtx *svc.ServiceContext) gin.HandlerFunc {
return func(c *gin.Context) {
var req deleteAccountReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request: " + err.Error()})
return
}
// 校验邮箱验证码
if err := verifyEmailCode(c.Request.Context(), serverCtx, req.Code); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
l := user.NewDeleteAccountLogic(c.Request.Context(), serverCtx)
resp, err := l.DeleteAccount()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, resp)
}
}
type CacheKeyPayload struct {
Code string `json:"code"`
LastAt int64 `json:"lastAt"`
}
func verifyEmailCode(ctx context.Context, serverCtx *svc.ServiceContext, code string) error {
return nil
}