@@ -2,6 +2,8 @@ package basicuser
22
33import (
44 "context"
5+ "fmt"
6+ "strconv"
57
68 model "github.com/xh-polaris/synapse/biz/api/model/basicuser"
79 "github.com/xh-polaris/synapse/biz/application/base/token"
@@ -10,9 +12,11 @@ import (
1012 "github.com/xh-polaris/synapse/biz/conf"
1113 "github.com/xh-polaris/synapse/biz/domain/basicuser/entity"
1214 basicuser "github.com/xh-polaris/synapse/biz/domain/basicuser/service"
15+ "github.com/xh-polaris/synapse/biz/infra/contract/risk"
1316 "github.com/xh-polaris/synapse/biz/infra/contract/sms"
1417 ctxcache "github.com/xh-polaris/synapse/biz/pkg/ctxcache/ctx_cache"
1518 "github.com/xh-polaris/synapse/biz/pkg/errorx"
19+ "github.com/xh-polaris/synapse/biz/pkg/logs"
1620 "github.com/xh-polaris/synapse/biz/types/cst"
1721 "github.com/xh-polaris/synapse/biz/types/errno"
1822)
@@ -69,11 +73,23 @@ func (s *BasicUserService) RegisterNewBasicUser(ctx context.Context, req *model.
6973}
7074
7175func (s * BasicUserService ) validPhoneVerify (ctx context.Context , app , phone , code string ) error {
76+ // 判断是否到上限
77+ key := fmt .Sprintf ("risk:login:passport:%s" , phone )
78+ limit , _ , err := risk .CheckUpperLimit (ctx , key , conf .GetConfig ().Token .MaxInPeriod )
79+ if err != nil {
80+ return err
81+ }
82+ if limit { // 达到上限, 不允许校验
83+ return errorx .New (errno .TooOftenLoginError , errorx .KV ("period" , strconv .Itoa (conf .GetConfig ().SMS .Period / 60 )))
84+ }
7285 ok , err := s .sms .Check (ctx , app , "passport" , phone , code )
7386 if err != nil {
7487 return err
7588 }
7689 if ! ok {
90+ if err = risk .AddOnce (ctx , key , conf .GetConfig ().Token .Period ); err != nil {
91+ logs .Errorf ("record send verify err:%s" , err )
92+ }
7793 return errorx .New (errno .ErrVerifyCode )
7894 }
7995 return err
0 commit comments