-
Notifications
You must be signed in to change notification settings - Fork 0
Add resetPassword method to UserRepository for password reset functionality
#314
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
Add resetPassword method to UserRepository for password reset functionality
#314
Conversation
zigzagdev
left a comment
There was a problem hiding this 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
There was a problem hiding this 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'); |
Copilot
AI
Jun 29, 2025
There was a problem hiding this comment.
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.
|
|
||
| $updatedUser = $this->user->find($this->user->id); | ||
|
|
||
| $this->assertTrue( | ||
| Hash::check($newPassword, $updatedUser->password) | ||
| ); |
Copilot
AI
Jun 29, 2025
There was a problem hiding this comment.
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.
| $updatedUser = $this->user->find($this->user->id); | |
| $this->assertTrue( | |
| Hash::check($newPassword, $updatedUser->password) | |
| ); |
Description
Added a
resetPasswordmethod to theUserRepositorythat 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
UserIdException('User not found')PasswordHasherInterfaceto hash the new passwordupdate()method