Skip to content

Conversation

@zigzagdev
Copy link
Owner

Description

Added a resetPassword method to the UserRepository that updates the user's password based on their ID and a validated token. This method hashes the new password and updates it in the database.

Implementation Details

  • Retrieves the user by UserId
  • If the user does not exist, throws Exception('User not found')
  • Uses PasswordHasherInterface to hash the new password
  • Updates the user’s password in the database using Eloquent’s update() method

Copy link
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self Review

  • Validates user existence via UserId
  • Hashes the password through PasswordHasherInterface abstraction
  • Keeps domain logic separated from infrastructure concerns
  • Error handling for missing user is in place

@zigzagdev zigzagdev requested a review from Copilot June 29, 2025 09:58
@zigzagdev zigzagdev self-assigned this Jun 29, 2025
@zigzagdev zigzagdev added enhancement New feature or request backend test labels Jun 29, 2025
@zigzagdev zigzagdev linked an issue Jun 29, 2025 that may be closed by this pull request
@zigzagdev zigzagdev merged commit 4613297 into feature/user-password-reset-infra Jun 29, 2025
@zigzagdev zigzagdev deleted the feature/user-password-reset-infra-repository branch June 29, 2025 09:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new resetPassword method to the UserRepository to enable password resets by updating the user's hashed password in the database based on a validated reset token.

  • Implements the resetPassword method in the repository
  • Adds corresponding tests covering both successful and failure scenarios
  • Updates the UserRepository interface to include the new method

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/app/User/Infrastructure/Repository/UserRepository.php Adds resetPassword implementation using a generic Exception if user is not found
src/app/User/Infrastructure/InfrastructureTest/UserRepository_resetPasswordTest.php Provides tests for valid and invalid user password resets
src/app/User/Domain/RepositoryInterface/UserRepositoryInterface.php Updates the interface to declare resetPassword

$userModel = $this->user->find($userId->getValue());

if ($userModel === null) {
throw new Exception('User not found');
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a domain-specific exception (e.g., UserNotFoundException) instead of a generic Exception to improve error handling clarity.

Copilot uses AI. Check for mistakes.
Comment on lines +89 to +94

$updatedUser = $this->user->find($this->user->id);

$this->assertTrue(
Hash::check($newPassword, $updatedUser->password)
);
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code following the expected exception call in the invalid user test is unreachable; consider removing these assertions to clarify the test intent.

Suggested change
$updatedUser = $this->user->find($this->user->id);
$this->assertTrue(
Hash::check($newPassword, $updatedUser->password)
);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend enhancement New feature or request test

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Password Reset Infrastructure UserRepository

2 participants