From 9f4a29941c0a4274196aa4f6eb22c77e0b98f25a Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Mon, 12 Jun 2017 22:38:35 +0200 Subject: [PATCH] add reset password events docs --- docs/events/reset-password-events.md | 54 +++++++++++++++++++++++++++ src/User/Event/ResetPasswordEvent.php | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/events/reset-password-events.md b/docs/events/reset-password-events.md index e69de29..4108ed0 100644 --- a/docs/events/reset-password-events.md +++ b/docs/events/reset-password-events.md @@ -0,0 +1,54 @@ +Reset Password Events +===================== + +The following is the list of the reset password events and where they happen: + +On Controllers +-------------- + +- **RecoveryController** + - **ResetPasswordEvent::EVENT_BEFORE_TOKEN_VALIDATE**: Occurs before a reset password token is validated + - **ResetPasswordEvent::EVENT_AFTER_RESET**: Occurs after the password has been reset + +How to Work With Reset Password Events +-------------------------------------- + +This event is a bit more special than the others. When the token is about to be validated and the +`EVENT_BEFORE_TOKEN_VALIDATE` is raised, only contains an instance of `Da\User\Model\Token` model and is accessible via +`Da\Form\ResetPasswordEvent::getToken()` method. But after the token is successfully validated, then when the +`Event_AFTER_RESET` is triggered, you can also access a `Da\User\Form\RecoveryForm` instance via its +`Da\Form\ResetPasswordEvent::getToken()` method. + +Check the following code as an example: + +```php +getToken(); // $token is a Da\User\Model\Token instance + $form = $event->getForm(); // form is NULL + + // ... your logic here + }); + +Event::on( + RecoveryController::class, + ResetPasswordEvent::EVENT_AFTER_RESET, + function (ResetPasswordEvent $event) { + + $token = $event->getToken(); // $token is a Da\User\Model\Token instance + $form = $event->getForm(); // form is a Da\User\Form\RecoveryForm instance with submitted data + + // ... your logic here + }); + +``` diff --git a/src/User/Event/ResetPasswordEvent.php b/src/User/Event/ResetPasswordEvent.php index a28436a..4cc21d0 100644 --- a/src/User/Event/ResetPasswordEvent.php +++ b/src/User/Event/ResetPasswordEvent.php @@ -25,7 +25,7 @@ class ResetPasswordEvent extends Event protected $form; protected $token; - public function __construct(Token $token, RecoveryForm $form, array $config = []) + public function __construct(Token $token = null, RecoveryForm $form = null, array $config = []) { $this->form = $form; $this->token = $token;