diff --git a/config.yaml.sample b/config.yaml.sample index 92c7046f..90d20f6c 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -5,6 +5,7 @@ App: # APP基础设置项 DefaultContextTimeout: 60 DefaultPageSize: 10 MaxPageSize: 100 + UserPhoneLimitation: 2 Server: # 服务设置 RunMode: debug HttpIp: 0.0.0.0 diff --git a/internal/conf/setting.go b/internal/conf/setting.go index 913e6a8d..b1ff1cc8 100644 --- a/internal/conf/setting.go +++ b/internal/conf/setting.go @@ -106,6 +106,7 @@ type appConf struct { DefaultContextTimeout time.Duration DefaultPageSize int MaxPageSize int + UserPhoneLimitation int } type cacheConf struct { diff --git a/internal/core/core.go b/internal/core/core.go index bb3a0d5c..4f1e17a1 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -41,6 +41,9 @@ type DataService interface { // 安全服务 SecurityService AttachmentCheckService + + // 实用性服务 + //StickerService } // WebDataServantA Web数据服务集成(版本A) diff --git a/internal/core/user.go b/internal/core/user.go index 78ac1c8d..1b3f7209 100644 --- a/internal/core/user.go +++ b/internal/core/user.go @@ -13,7 +13,7 @@ import ( type UserManageService interface { GetUserByID(id int64) (*ms.User, error) GetUserByUsername(username string) (*ms.User, error) - GetUserByPhone(phone string) (*ms.User, error) + GetUserByPhone(phone string) ([]*ms.User, error) GetUsersByIDs(ids []int64) ([]*ms.User, error) GetUsersByKeyword(keyword string) ([]*ms.User, error) UserProfileByName(username string) (*cs.UserProfile, error) diff --git a/internal/dao/jinzhu/user.go b/internal/dao/jinzhu/user.go index d7d7afc3..9d86b492 100644 --- a/internal/dao/jinzhu/user.go +++ b/internal/dao/jinzhu/user.go @@ -90,11 +90,13 @@ func (s *userManageSrv) UserProfileByName(username string) (res *cs.UserProfile, return } -func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { +func (s *userManageSrv) GetUserByPhone(phone string) ([]*ms.User, error) { user := &dbr.User{ Phone: phone, } - return user.Get(s.db) + return user.List(s.db, &dbr.ConditionsT{ + "phone = ?": phone, + }, 0, 0) } func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { diff --git a/internal/model/web/xerror.go b/internal/model/web/xerror.go index d67fd519..cd27c905 100644 --- a/internal/model/web/xerror.go +++ b/internal/model/web/xerror.go @@ -26,7 +26,7 @@ var ( ErrTooManyLoginError = xerror.NewError(20014, "登录失败次数过多,请稍后再试") ErrGetPhoneCaptchaError = xerror.NewError(20015, "短信验证码获取失败") ErrTooManyPhoneCaptchaSend = xerror.NewError(20016, "短信验证码获取次数已达今日上限") - ErrExistedUserPhone = xerror.NewError(20017, "该手机号已被绑定") + ErrUserPhoneLimit = xerror.NewError(20017, "该手机号绑定超限") ErrErrorPhoneCaptcha = xerror.NewError(20018, "手机验证码不正确") ErrMaxPhoneCaptchaUseTimes = xerror.NewError(20019, "手机验证码已达最大使用次数") ErrNicknameLengthLimit = xerror.NewError(20020, "昵称长度2~12") diff --git a/internal/servants/web/core.go b/internal/servants/web/core.go index d3c0ef4a..1d1edb38 100644 --- a/internal/servants/web/core.go +++ b/internal/servants/web/core.go @@ -238,9 +238,20 @@ func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollection func (s *coreSrv) UserPhoneBind(req *web.UserPhoneBindReq) error { // 手机重复性检查 + maxBind := conf.AppSetting.UserPhoneLimitation + u, err := s.Ds.GetUserByPhone(req.Phone) - if err == nil && u.Model != nil && u.ID != 0 && u.ID != req.User.ID { - return web.ErrExistedUserPhone + if err == nil && len(u) > 0 { + // 检查是否有其他用户已绑定此手机号 + for _, user := range u { + if user.ID != req.User.ID { + // 如果发现其他用户已绑定,且达到限制数量,则返回错误 + if len(u) >= maxBind { + return web.ErrUserPhoneLimit + } + break // 只需找到一个非当前用户绑定记录即可 + } + } } // 如果禁止phone verify 则允许通过任意验证码