-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLostPasswordFormTrait.php
More file actions
56 lines (46 loc) · 1.75 KB
/
Copy pathLostPasswordFormTrait.php
File metadata and controls
56 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace ADT\FancyAdmin\UI\Components\Forms\LostPassword;
use ADT\DoctrineAuthenticator\OTP\OnetimeToken;
use ADT\FancyAdmin\DI\Injects\AuthenticatorInject;
use ADT\FancyAdmin\DI\Injects\FancyAdminInject;
use ADT\FancyAdmin\DI\Injects\IdentityQueryFactoryInject;
use ADT\FancyAdmin\DI\Injects\MailerInject;
use ADT\FancyAdmin\Model\Entities\Identity;
use ADT\FancyAdmin\UI\Components\ControlTrait;
use ADT\Forms\Form;
trait LostPasswordFormTrait
{
use ControlTrait;
use IdentityQueryFactoryInject;
use MailerInject;
use AuthenticatorInject;
use FancyAdminInject;
public function initForm(Form $form): void
{
$form->getElementPrototype()->class[] = 'login-form';
$form->addEmail('email')
->setHtmlAttribute('placeholder', 'fcadmin.forms.lostPassword.labels.email')
->setRequired('fcadmin.forms.lostPassword.errors.emailRequired');
$form->addSubmit('submit', 'fcadmin.forms.lostPassword.labels.submit');
$form->getComponentSubmitButton('submit')->getControlPrototype()->class[] = 'w-100';
}
public function processForm(array $values): never
{
/** @var Identity $identity */
if (!$identity = $this->_authenticator->findIdentity($values['email'], $this->_fancyAdmin->getContext())) {
$this->getPresenter()->flashMessageError('fcadmin.forms.lostPassword.messages.error');
$this->getPresenter()->redirect('this');
}
$this->_mailer->sendPasswordRecoveryMail($identity, OnetimeToken::PASSWORD_RECOVERY_VALID_FOR);
$this->processFormRedirect($identity);
}
public function getEntityClass(): ?string
{
return null;
}
protected function processFormRedirect(Identity $identity): never
{
$this->getPresenter()->flashMessageSuccess('fcadmin.forms.lostPassword.messages.success');
$this->getPresenter()->redirect('lostPassword');
}
}