add reset password events docs

This commit is contained in:
Antonio Ramirez
2017-06-12 22:38:35 +02:00
parent 852fc0e3bb
commit 9f4a29941c
2 changed files with 55 additions and 1 deletions

View File

@ -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
<?php
// events.php file
use Da\Controller\RecoveryController;
use Da\Event\ResetPasswordEvent;
use yii\base\Event;
Event::on(
RecoveryController::class,
ResetPasswordEvent::EVENT_BEFORE_TOKEN_VALIDATE,
function (ResetPasswordEvent $event) {
$token = $event->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
});
```