|
@@ -1,7 +1,9 @@
|
|
|
package user
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"errors"
|
|
|
+ "hongze/hongze_yb/global"
|
|
|
userReq "hongze/hongze_yb/models/request/user"
|
|
|
admin2 "hongze/hongze_yb/models/tables/admin"
|
|
|
"hongze/hongze_yb/models/tables/company"
|
|
@@ -432,6 +434,13 @@ func GetUserTabBar(userInfo user.UserInfo, version string) (list []string, err e
|
|
|
|
|
|
// PcSendSmsCode 发送手机短信
|
|
|
func PcSendSmsCode(mobile, areaNum string) (err error, errMsg string) {
|
|
|
+ cacheKey := utils.HONGZEYB_ + "REPORT_SMS_CODE_PC:GetSmsCode:" + areaNum + ":" + mobile
|
|
|
+ smsCodeStr, _ := global.Redis.Get(context.TODO(), cacheKey).Result()
|
|
|
+ if smsCodeStr != "" {
|
|
|
+ err = errors.New("请勿频繁发送验证码")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if mobile == "" {
|
|
|
err = errors.New("请输入手机号")
|
|
|
return
|
|
@@ -447,6 +456,7 @@ func PcSendSmsCode(mobile, areaNum string) (err error, errMsg string) {
|
|
|
}
|
|
|
//发送成功
|
|
|
if result {
|
|
|
+ // 验证码存库
|
|
|
item := &msg_code.MsgCode{
|
|
|
Mobile: mobile,
|
|
|
Code: msgCode,
|
|
@@ -456,6 +466,7 @@ func PcSendSmsCode(mobile, areaNum 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("短信发送失败")
|
|
|
}
|
|
@@ -472,6 +483,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 := "弘则研究登陆验证"
|
|
@@ -488,6 +506,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("发送失败")
|
|
|
}
|