Skip to content

Commit

Permalink
Add emailRegister check (#308)
Browse files Browse the repository at this point in the history
* fix bug

* Your commit message

* fix bug register email

* fix bug email resetpassword

* fix bug mysql sleep

* fix bug login.go

* fix bug login.go

* fix bug login.go

* fix bug login.go

* fix bug login.go

* fix bug login.go

* fix bug pb

* fix bug pb

* update to adjust more type
  • Loading branch information
AndrewZuo01 authored Dec 18, 2023
1 parent 0140e82 commit 49822f9
Show file tree
Hide file tree
Showing 9 changed files with 684 additions and 633 deletions.
6 changes: 6 additions & 0 deletions internal/rpc/chat/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (
return nil, err
}
}
var registerType int32
if req.User.PhoneNumber != "" {
if req.User.AreaCode[0] != '+' {
req.User.AreaCode = "+" + req.User.AreaCode
Expand All @@ -337,7 +338,9 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (
} else if !o.Database.IsNotFound(err) {
return nil, err
}
registerType = constant.PhoneRegister
}

if req.User.Account != "" {
_, err := o.Database.TakeAttributeByAccount(ctx, req.User.Account)
if err == nil {
Expand All @@ -346,8 +349,10 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (
return nil, err
}
}

if req.User.Email != "" {
_, err := o.Database.TakeAttributeByEmail(ctx, req.User.Email)
registerType = constant.EmailRegister
if err == nil {
return nil, eerrs.ErrEmailAlreadyRegister.Wrap()
} else if !o.Database.IsNotFound(err) {
Expand Down Expand Up @@ -385,6 +390,7 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (
AllowVibration: constant.DefaultAllowVibration,
AllowBeep: constant.DefaultAllowBeep,
AllowAddFriend: constant.DefaultAllowAddFriend,
RegisterType: registerType,
}
if err := o.Database.RegisterUser(ctx, register, account, attribute); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions internal/rpc/chat/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func DbToPbUserFullInfo(attribute *chat.Attribute) *common.UserFullInfo {
AllowBeep: attribute.AllowBeep,
AllowVibration: attribute.AllowVibration,
GlobalRecvMsgOpt: attribute.GlobalRecvMsgOpt,
RegisterType: attribute.RegisterType,
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/common/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,8 @@ const (
const DefaultPlatform = 1

const CtxApiToken = "api-token"

const (
EmailRegister = 1
PhoneRegister = 2
)
1 change: 1 addition & 0 deletions pkg/common/db/table/chat/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Attribute struct {
AllowBeep int32 `gorm:"column:allow_beep;default:1"`
AllowAddFriend int32 `gorm:"column:allow_add_friend;default:1"`
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt;default:0"`
RegisterType int32 `gorm:"column:register_type"`
}

func (Attribute) TableName() string {
Expand Down
48 changes: 24 additions & 24 deletions pkg/proto/admin/admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 49822f9

Please sign in to comment.