mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
fix password reset flow
This commit is contained in:
@@ -117,7 +117,7 @@ func (domain *Domain) SavePasswordResetCode(ctx context.Context, userID, code st
|
|||||||
return &pwcode, err
|
return &pwcode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (domain *Domain) DeletePasswordRestCode(ctx context.Context, userId, code string) error {
|
func (domain *Domain) DeletePasswordResetCode(ctx context.Context, userId, code string) error {
|
||||||
_, err := domain.db.Delete(ctx, &db.DeleteRequest{
|
_, err := domain.db.Delete(ctx, &db.DeleteRequest{
|
||||||
Table: "password-reset-codes",
|
Table: "password-reset-codes",
|
||||||
Id: userId + "-" + code,
|
Id: userId + "-" + code,
|
||||||
|
|||||||
@@ -335,8 +335,14 @@ func (s *User) ResetPassword(ctx context.Context, req *pb.ResetPasswordRequest,
|
|||||||
return errors.BadRequest("user.resetpassword", "passwords do not match")
|
return errors.BadRequest("user.resetpassword", "passwords do not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// look for an existing user
|
||||||
|
users, err := s.domain.Search(ctx, "", req.Email)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// check if a request was made to reset the password, we should have saved it
|
// check if a request was made to reset the password, we should have saved it
|
||||||
code, err := s.domain.ReadPasswordResetCode(ctx, req.Email, req.Code)
|
code, err := s.domain.ReadPasswordResetCode(ctx, users[0].Id, req.Code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -369,7 +375,7 @@ func (s *User) ResetPassword(ctx context.Context, req *pb.ResetPasswordRequest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// delete our saved code
|
// delete our saved code
|
||||||
s.domain.DeletePasswordRestCode(ctx, req.Email, req.Code)
|
s.domain.DeletePasswordResetCode(ctx, users[0].Id, req.Code)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user