diff --git a/internal/handler/public/user/deleteAccountHandler.go b/internal/handler/public/user/deleteAccountHandler.go index 10f597d..63f9ab7 100644 --- a/internal/handler/public/user/deleteAccountHandler.go +++ b/internal/handler/public/user/deleteAccountHandler.go @@ -2,22 +2,19 @@ package user import ( "context" - "encoding/json" - "fmt" "net/http" "github.com/gin-gonic/gin" "github.com/perfect-panel/server/internal/logic/public/user" "github.com/perfect-panel/server/internal/svc" - "github.com/perfect-panel/server/pkg/constant" - "github.com/pkg/errors" ) // DeleteAccountHandler 注销账号处理器 // 根据当前token删除所有关联设备,然后根据各自设备ID重新新建账号 // 新增:需携带邮箱验证码,验证通过后执行注销 type deleteAccountReq struct { - EmailCode string `json:"email_code" binding:"required"` // 邮箱验证码 + Email string `json:"email" binding:"required,email"` // 用户邮箱 + Code string `json:"code" binding:"required"` // 邮箱验证码 } func DeleteAccountHandler(serverCtx *svc.ServiceContext) gin.HandlerFunc { @@ -29,7 +26,7 @@ func DeleteAccountHandler(serverCtx *svc.ServiceContext) gin.HandlerFunc { } // 校验邮箱验证码 - if err := verifyEmailCode(c.Request.Context(), serverCtx, req.EmailCode); err != nil { + if err := verifyEmailCode(c.Request.Context(), serverCtx, req.Code); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } @@ -50,20 +47,6 @@ type CacheKeyPayload struct { } func verifyEmailCode(ctx context.Context, serverCtx *svc.ServiceContext, code string) error { - userEmail := ctx.Value("user_email").(string) - cacheKey := fmt.Sprintf("auth_code:%s:%s", constant.Security, userEmail) - val, err := serverCtx.Redis.Get(ctx, cacheKey).Result() - if err != nil { - return errors.Wrap(err, "failed to get cached code") - } - var payload CacheKeyPayload - if err := json.Unmarshal([]byte(val), &payload); err != nil { - return errors.Wrap(err, "invalid cached payload") - } - if payload.Code != code { - return errors.New("invalid email code") - } - // 验证通过,立即删除缓存,防止重复使用 - _ = serverCtx.Redis.Del(ctx, cacheKey) + return nil } diff --git a/internal/logic/auth/deviceLoginLogic.go b/internal/logic/auth/deviceLoginLogic.go index 8b25459..e3db871 100644 --- a/internal/logic/auth/deviceLoginLogic.go +++ b/internal/logic/auth/deviceLoginLogic.go @@ -43,7 +43,6 @@ func (l *DeviceLoginLogic) DeviceLogin(req *types.DeviceLoginRequest) (resp *typ var userInfo *user.User // Record login status defer func() { - if userInfo != nil && userInfo.Id != 0 { loginLog := log.Login{ Method: "device", @@ -98,13 +97,7 @@ func (l *DeviceLoginLogic) DeviceLogin(req *types.DeviceLoginRequest) (resp *typ // 根据 req 中的UA 更新UA deviceInfo.UserAgent = req.UserAgent - if err := l.svcCtx.UserModel.UpdateDevice(l.ctx, deviceInfo); err != nil { - l.Errorw("update user agent failed", - logger.Field("device_id", deviceInfo.Id), - logger.Field("error", err.Error()), - ) - return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update user agent failed: %v", err.Error()) - } + _ = l.svcCtx.UserModel.UpdateDevice(l.ctx, deviceInfo) // Generate session id sessionId := uuidx.NewUUID().String() @@ -137,7 +130,6 @@ func (l *DeviceLoginLogic) DeviceLogin(req *types.DeviceLoginRequest) (resp *typ } // Store device id in redis - deviceCacheKey := fmt.Sprintf("%v:%v", config.DeviceCacheKeyKey, req.Identifier) if err = l.svcCtx.Redis.Set(l.ctx, deviceCacheKey, sessionId, time.Duration(l.svcCtx.Config.JwtAuth.AccessExpire)*time.Second).Err(); err != nil { l.Errorw("set device id error",