add reset password events docs
This commit is contained in:
@ -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
|
||||||
|
});
|
||||||
|
|
||||||
|
```
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class ResetPasswordEvent extends Event
|
|||||||
protected $form;
|
protected $form;
|
||||||
protected $token;
|
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->form = $form;
|
||||||
$this->token = $token;
|
$this->token = $token;
|
||||||
|
|||||||
Reference in New Issue
Block a user