(c *gin.Context)
| 270 | } |
| 271 | |
| 272 | func ResetPassword(c *gin.Context) { |
| 273 | var req PasswordResetRequest |
| 274 | err := json.NewDecoder(c.Request.Body).Decode(&req) |
| 275 | if req.Email == "" || req.Token == "" { |
| 276 | c.JSON(http.StatusOK, gin.H{ |
| 277 | "success": false, |
| 278 | "message": "无效的参数", |
| 279 | }) |
| 280 | return |
| 281 | } |
| 282 | if !common.VerifyCodeWithKey(req.Email, req.Token, common.PasswordResetPurpose) { |
| 283 | c.JSON(http.StatusOK, gin.H{ |
| 284 | "success": false, |
| 285 | "message": "重置链接非法或已过期", |
| 286 | }) |
| 287 | return |
| 288 | } |
| 289 | password := common.GenerateVerificationCode(12) |
| 290 | err = model.ResetUserPasswordByEmail(req.Email, password) |
| 291 | if err != nil { |
| 292 | common.ApiError(c, err) |
| 293 | return |
| 294 | } |
| 295 | common.DeleteKey(req.Email, common.PasswordResetPurpose) |
| 296 | c.JSON(http.StatusOK, gin.H{ |
| 297 | "success": true, |
| 298 | "message": "", |
| 299 | "data": password, |
| 300 | }) |
| 301 | return |
| 302 | } |
nothing calls this directly
no test coverage detected