api change user password

This commit is contained in:
Efril
2026-01-14 14:08:27 +07:00
parent 057cccfef9
commit c8ea680e05
11 changed files with 89 additions and 23 deletions
+20 -1
View File
@@ -125,7 +125,7 @@ func (p *UserProcessorImpl) UpdateUser(ctx context.Context, id uuid.UUID, req *c
return nil, fmt.Errorf("failed to update user: %w", err)
}
if(req.Name != nil) {
if req.Name != nil {
profile, err := p.profileRepo.GetByUserID(ctx, updated.ID)
if err != nil {
return nil, fmt.Errorf("failed to get user profile: %w", err)
@@ -293,6 +293,25 @@ func (p *UserProcessorImpl) ChangePassword(ctx context.Context, userID uuid.UUID
return nil
}
func (p *UserProcessorImpl) ChangeUserPassword(ctx context.Context, userID uuid.UUID, req *contract.ChangeUserPasswordRequest) error {
_, err := p.userRepo.GetByID(ctx, userID)
if err != nil {
return fmt.Errorf("user not found: %w", err)
}
newPasswordHash, err := bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost)
if err != nil {
return fmt.Errorf("failed to hash new password: %w", err)
}
err = p.userRepo.UpdatePassword(ctx, userID, string(newPasswordHash))
if err != nil {
return fmt.Errorf("failed to update password: %w", err)
}
return nil
}
func (p *UserProcessorImpl) ActivateUser(ctx context.Context, userID uuid.UUID) error {
_, err := p.userRepo.GetByID(ctx, userID)
if err != nil {