🎨 完善注册逻辑

This commit is contained in:
2025-07-20 02:11:19 +08:00
parent f86b56a79d
commit c3d5d532cd

View File

@@ -8,7 +8,6 @@ import (
common "git.echol.cn/loser/lckt/model/common/request" common "git.echol.cn/loser/lckt/model/common/request"
"git.echol.cn/loser/lckt/model/user" "git.echol.cn/loser/lckt/model/user"
"git.echol.cn/loser/lckt/model/user/request" "git.echol.cn/loser/lckt/model/user/request"
"git.echol.cn/loser/lckt/utils/sms"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"math/rand" "math/rand"
@@ -36,18 +35,19 @@ func (u *UserService) SendCode(req request.SendCodeReq) (err error) {
result, err := rdb.Get(context.Background(), key).Result() result, err := rdb.Get(context.Background(), key).Result()
if result != "" { if result != "" {
global.GVA_LOG.Error("验证码发送过于频繁", zap.String("phone", req.Phone)) global.GVA_LOG.Error("验证码发送过于频繁", zap.String("phone", req.Phone))
err = fmt.Errorf("验证码发送过于频繁,请稍后再试")
return return
} }
rand.New(rand.NewSource(time.Now().UnixNano())) rand.New(rand.NewSource(time.Now().UnixNano()))
verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000)) verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000))
if ok := sms.SendSMS(req.Phone, verifyCode); !ok { //if ok := sms.SendSMS(req.Phone, verifyCode); !ok {
global.GVA_LOG.Error("发送验证码失败") // global.GVA_LOG.Error("发送验证码失败")
return // return
} //}
// //
if err = rdb.Set(context.Background(), key, verifyCode, time.Duration(global.GVA_CONFIG.SMS.ExpireTime)*time.Second).Err(); err != nil { if err = rdb.Set(context.Background(), key, verifyCode, 5*time.Minute).Err(); err != nil {
global.GVA_LOG.Error("设置验证码缓存失败", zap.Error(err)) global.GVA_LOG.Error("设置验证码缓存失败", zap.Error(err))
return return
} }