Skip to content

Commit

Permalink
fix: Reset password by email failed (openimsdk#595)
Browse files Browse the repository at this point in the history
* fix: ResetPasswordReq pb

* fix: reset psw error

* Revert "fix: ResetPasswordReq pb"

This reverts commit 7e884dc225a523e219333332859ec236a2b3fdd1.
  • Loading branch information
icey-yu authored Oct 21, 2024
1 parent dcd7586 commit 40fe993
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
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

0 comments on commit 40fe993

Please sign in to comment.