Browse Source

233-登录验证码获取限制-邮箱限制

gmy 6 months ago
parent
commit
91476e1bfa
2 changed files with 10 additions and 0 deletions
  1. 2 0
      controller/pc/pc.go
  2. 8 0
      logic/user/user.go

+ 2 - 0
controller/pc/pc.go

@@ -935,6 +935,8 @@ func GetEmailCode(c *gin.Context) {
 	if err != nil {
 		if errMsg != "" {
 			errMsg = "获取验证码失败"
+		} else {
+			errMsg = err.Error()
 		}
 		response.Fail(errMsg, c)
 		return

+ 8 - 0
logic/user/user.go

@@ -482,6 +482,13 @@ func PcSendEmailCode(email string) (err error, errMsg string) {
 		err = errors.New("邮箱格式错误,请重新输入")
 		return
 	}
+	cacheKey := utils.HONGZEYB_ + "REPORT_SMS_CODE_PC:PcSendEmailCode:" + email
+	smsCodeStr, _ := global.Redis.Get(context.TODO(), cacheKey).Result()
+	if smsCodeStr != "" {
+		err = errors.New("请勿频繁发送验证码")
+		return
+	}
+
 	msgCode := utils.GetRandDigit(4)
 	content := "尊敬的用户:</br>您好,感谢您使用弘则研究,您正在进行邮箱验证,本次请求的验证码为:" + msgCode + "(为了保障您账号的安全性,请在15分钟内完成验证。)</br>弘则研究团队 </br>" + time.Now().Format(utils.FormatDateCN)
 	title := "弘则研究登陆验证"
@@ -498,6 +505,7 @@ func PcSendEmailCode(email string) (err error, errMsg string) {
 			LastUpdatedTime: time.Time{},
 		}
 		err = item.Create()
+		global.Redis.Set(context.TODO(), cacheKey, msgCode, 60*time.Second)
 	} else {
 		err = errors.New("发送失败")
 	}