修改手机号绑定上限

pull/701/head
miaowuawa 1 year ago
parent 61c9083ceb
commit 37e54bd526

@ -5,6 +5,7 @@ App: # APP基础设置项
DefaultContextTimeout: 60
DefaultPageSize: 10
MaxPageSize: 100
UserPhoneLimitation: 2
Server: # 服务设置
RunMode: debug
HttpIp: 0.0.0.0

@ -106,6 +106,7 @@ type appConf struct {
DefaultContextTimeout time.Duration
DefaultPageSize int
MaxPageSize int
UserPhoneLimitation int
}
type cacheConf struct {

@ -41,6 +41,9 @@ type DataService interface {
// 安全服务
SecurityService
AttachmentCheckService
// 实用性服务
//StickerService
}
// WebDataServantA Web数据服务集成(版本A)

@ -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)

@ -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) {

@ -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")

@ -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 则允许通过任意验证码

Loading…
Cancel
Save