diff --git a/controller/user.go b/controller/user.go index 000a8cb..e56a97c 100644 --- a/controller/user.go +++ b/controller/user.go @@ -96,7 +96,7 @@ func (_UserController) InvalidUserPassword(c *gin.Context) { result.Error(500, err.Error()) return } - result.QuickJson(http.StatusOK, http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode}) + result.Json(http.StatusOK, http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode}) } type ResetPasswordFormData struct { @@ -110,14 +110,18 @@ func (_UserController) ResetUserPassword(c *gin.Context) { resetForm := new(ResetPasswordFormData) c.BindJSON(resetForm) verified, err := service.UserService.VerifyUserPassword(resetForm.Username, resetForm.VerifyCode) - if !verified { - result.Error(http.StatusUnauthorized, "验证码不正确。") + if errors.Is(err, &exceptions.NotFoundError{}) { + result.NotFound("指定的用户不存在。") return } if err != nil { result.Error(http.StatusInternalServerError, err.Error()) return } + if !verified { + result.Error(http.StatusUnauthorized, "验证码不正确。") + return + } completed, err := service.UserService.ResetUserPassword(resetForm.Username, resetForm.NewPassword) if err != nil { result.Error(http.StatusInternalServerError, err.Error()) @@ -127,5 +131,5 @@ func (_UserController) ResetUserPassword(c *gin.Context) { result.Success("用户凭据已更新。") return } - result.Error(http.StatusNotAcceptable, "用户凭据未能成功更新。") + result.NotAccept("用户凭据未能成功更新。") } diff --git a/response/base_response.go b/response/base_response.go index 58e8ed0..df479c7 100644 --- a/response/base_response.go +++ b/response/base_response.go @@ -15,6 +15,12 @@ type BaseResponse struct { Message string `json:"message"` } +type PagedResponse struct { + Page int `json:"page"` + Size int `json:"pageSize"` + Total int `json:"total"` +} + func NewResult(ctx *gin.Context) *Result { return &Result{Ctx: ctx} } @@ -77,7 +83,7 @@ func (r *Result) NotFound(msg string) { // 快速自由JSON格式响应 // ! 注意,给定的map中,同名的键会被覆盖。 -func (r *Result) QuickJson(status, code int, msg string, payloads ...map[string]interface{}) { +func (r *Result) Json(status, code int, msg string, payloads ...map[string]interface{}) { var finalPayload = make(map[string]interface{}, 0) finalPayload["code"] = code finalPayload["message"] = &msg