diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.yml index 51bd3a65d..4b0526d1e 100644 --- a/.github/workflows/scripts-test.yml +++ b/.github/workflows/scripts-test.yml @@ -75,7 +75,7 @@ jobs: -v "/etc/localtime:/etc/localtime" \ -e MYSQL_ROOT_PASSWORD="openIM123" \ --restart always \ - mysql:5.7 + mysql:5.7 sleep 30; - name: start all services run: | diff --git a/internal/rpc/chat/login.go b/internal/rpc/chat/login.go index c8ded6fff..0472fa221 100644 --- a/internal/rpc/chat/login.go +++ b/internal/rpc/chat/login.go @@ -92,12 +92,22 @@ func (o *chatSvr) SendVerifyCode(ctx context.Context, req *chat.SendVerifyCodeRe } } case constant.VerificationCodeForLogin, constant.VerificationCodeForResetPassword: - _, err := o.Database.TakeAttributeByPhone(ctx, req.AreaCode, req.PhoneNumber) - if o.Database.IsNotFound(err) { - return nil, errs.ErrArgs.Wrap("phone unregistered") - } else if err != nil { - return nil, err + if req.Email == "" { + _, err := o.Database.TakeAttributeByPhone(ctx, req.AreaCode, req.PhoneNumber) + if o.Database.IsNotFound(err) { + return nil, eerrs.ErrAccountNotFound.Wrap("phone unregistered") + } else if err != nil { + return nil, err + } + } else { + _, err := o.Database.TakeAttributeByEmail(ctx, req.Email) + if o.Database.IsNotFound(err) { + return nil, eerrs.ErrAccountNotFound.Wrap("email unregistered") + } else if err != nil { + return nil, err + } } + default: return nil, errs.ErrArgs.Wrap("used unknown") } @@ -275,9 +285,16 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) ( return nil, err } } - if _, err := o.verifyCode(ctx, o.verifyCodeJoin(req.User.AreaCode, req.User.PhoneNumber), req.VerifyCode); err != nil { - return nil, err + if req.User.Email == "" { + if _, err := o.verifyCode(ctx, o.verifyCodeJoin(req.User.AreaCode, req.User.PhoneNumber), req.VerifyCode); err != nil { + return nil, err + } + } else { + if _, err := o.verifyCode(ctx, req.User.Email, req.VerifyCode); err != nil { + return nil, err + } } + } log.ZDebug(ctx, "usedInvitationCode", usedInvitationCode) if req.User.UserID == "" { @@ -427,7 +444,14 @@ func (o *chatSvr) Login(ctx context.Context, req *chat.LoginReq) (*chat.LoginRes } var verifyCodeID *uint if req.Password == "" { - id, err := o.verifyCode(ctx, o.verifyCodeJoin(req.AreaCode, req.PhoneNumber), req.VerifyCode) + var id uint + var err error + if req.Email == "" { + id, err = o.verifyCode(ctx, o.verifyCodeJoin(req.AreaCode, req.PhoneNumber), req.VerifyCode) + } else { + id, err = o.verifyCode(ctx, req.Email, req.VerifyCode) + } + if err != nil { return nil, err } diff --git a/internal/rpc/chat/password.go b/internal/rpc/chat/password.go index b865d9564..37c828932 100644 --- a/internal/rpc/chat/password.go +++ b/internal/rpc/chat/password.go @@ -16,7 +16,6 @@ package chat import ( "context" - "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/errs" @@ -31,7 +30,14 @@ func (o *chatSvr) ResetPassword(ctx context.Context, req *chat.ResetPasswordReq) if req.Password == "" { return nil, errs.ErrArgs.Wrap("password must be set") } - verifyCodeID, err := o.verifyCode(ctx, o.verifyCodeJoin(req.AreaCode, req.PhoneNumber), req.VerifyCode) + var verifyCodeID uint + var err error + if req.Email == "" { + verifyCodeID, err = o.verifyCode(ctx, o.verifyCodeJoin(req.AreaCode, req.PhoneNumber), req.VerifyCode) + } else { + verifyCodeID, err = o.verifyCode(ctx, req.Email, req.VerifyCode) + } + if err != nil { return nil, err } diff --git a/pkg/proto/chat/chat.go b/pkg/proto/chat/chat.go index 96befab99..a37d06a60 100644 --- a/pkg/proto/chat/chat.go +++ b/pkg/proto/chat/chat.go @@ -269,7 +269,7 @@ func (x *SearchLogsReq) Check() error { } func EmailCheck(email string) error { - pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z]\.){1,4}[a-z]{2,4}$` + pattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$` if err := regexMatch(pattern, email); err != nil { return errs.Wrap(err, "Email is invalid") }