Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reset password by email failed #595

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions internal/rpc/chat/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package chat

import (
"context"

"github.com/openimsdk/tools/errs"

"github.com/openimsdk/chat/pkg/common/constant"
Expand All @@ -28,6 +27,11 @@ func (o *chatSvr) ResetPassword(ctx context.Context, req *chat.ResetPasswordReq)
if req.Password == "" {
return nil, errs.ErrArgs.WrapMsg("password must be set")
}
if req.AreaCode == "" || req.PhoneNumber == "" {
if !(req.AreaCode == "" && req.PhoneNumber == "") {
return nil, errs.ErrArgs.WrapMsg("area code and phone number must set together")
}
}
var verifyCodeID string
var err error
if req.Email == "" {
Expand All @@ -39,22 +43,19 @@ func (o *chatSvr) ResetPassword(ctx context.Context, req *chat.ResetPasswordReq)
if err != nil {
return nil, err
}

var account string
if req.Email == "" {
attribute, err := o.Database.TakeAttributeByPhone(ctx, req.AreaCode, req.PhoneNumber)
if err != nil {
return nil, err
}
err = o.Database.UpdatePasswordAndDeleteVerifyCode(ctx, attribute.UserID, req.Password, verifyCodeID)
account = BuildCredentialPhone(req.AreaCode, req.PhoneNumber)
} else {
attribute, err := o.Database.TakeAttributeByEmail(ctx, req.Email)
if err != nil {
return nil, err
}
err = o.Database.UpdatePasswordAndDeleteVerifyCode(ctx, attribute.UserID, req.Password, verifyCodeID)
if err != nil {
return nil, err
}
account = req.Email
}
cred, err := o.Database.TakeCredentialByAccount(ctx, account)
if err != nil {
return nil, err
}
err = o.Database.UpdatePasswordAndDeleteVerifyCode(ctx, cred.UserID, req.Password, verifyCodeID)
if err != nil {
return nil, err
}
return &chat.ResetPasswordResp{}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/common/db/database/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ func (o *ChatDatabase) UpdatePasswordAndDeleteVerifyCode(ctx context.Context, us
if err := o.account.UpdatePassword(ctx, userID, password); err != nil {
return err
}
if codeID == "" {
return nil
}
if err := o.verifyCode.Delete(ctx, codeID); err != nil {
return err
}
Expand Down
Loading