-
Notifications
You must be signed in to change notification settings - Fork 67
[persistence] remove ResetPasswordRequest objects programmatically #284
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,57 @@ _Optional_ - Defaults to `true` | |
Enable or disable the Reset Password Cleaner which handles expired reset password | ||
requests that may have been left in persistence. | ||
|
||
## Advanced Usage | ||
|
||
### Purging `ResetPasswordRequest` objects from persistence | ||
|
||
The `ResetPasswordRequestRepositoryInterface::removeRequests()` method, which is | ||
implemented in the | ||
[ResetPasswordRequestRepositoryTrait](https://github.com/SymfonyCasts/reset-password-bundle/blob/main/src/Persistence/Repository/ResetPasswordRequestRepositoryTrait.php), | ||
can be used to remove all request objects from persistence for a single user. This | ||
differs from the | ||
[garbage collection mechanism](https://github.com/SymfonyCasts/reset-password-bundle/blob/df64d82cca2ee371da5e8c03c227457069ae663e/src/Persistence/Repository/ResetPasswordRequestRepositoryTrait.php#L73) | ||
which only removes _expired_ request objects for _all_ users automatically. | ||
|
||
Typically, you'd call this method when you need to remove request object(s) for | ||
a user who changed their email address due to suspicious activity and potentially | ||
has valid request objects in persistence with their "old" compromised email address. | ||
|
||
This method relies on the user objects `primary key` being `immutable`. | ||
E.g. `User::id = UUID` not something like `User::id = '[email protected]'`. | ||
|
||
```php | ||
// ProfileController | ||
|
||
#[Route(path: '/profile/{id}', name: 'app_update_profile', methods: ['GET', 'POST'])] | ||
public function profile(Request $request, User $user, ResetPasswordRequestRepositoryInterface $repository): Response | ||
{ | ||
$form = $this->createFormBuilder($user) | ||
jrushlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
->add('email', EmailType::class) | ||
->add('save', SubmitType::class, ['label' => 'Save Profile']) | ||
->getForm() | ||
; | ||
|
||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$newEmail = $form->get('email')->getData(); | ||
|
||
if ($newEmail !== $user->getEmail()) { | ||
// The user changed their email address. | ||
// Remove any old reset requests for the user. | ||
$repository->removeRequests($user); | ||
} | ||
|
||
// Persist the user object... | ||
|
||
return $this->render('success.html.twig'); | ||
jrushlow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
return $this->render('profile.html.twig', ['form' => $form]); | ||
} | ||
``` | ||
jrushlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Support | ||
|
||
Feel free to open an issue for questions, problems, or suggestions with our bundle. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
/** | ||
* @author Jesse Rushlow <[email protected]> | ||
* @author Ryan Weaver <[email protected]> | ||
* | ||
* @method void removeRequests(object $user) Remove a users ResetPasswordRequest objects from persistence. | ||
*/ | ||
interface ResetPasswordRequestRepositoryInterface | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.