-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewPasswordFormTrait.php
More file actions
85 lines (70 loc) · 2.82 KB
/
Copy pathNewPasswordFormTrait.php
File metadata and controls
85 lines (70 loc) · 2.82 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace ADT\FancyAdmin\UI\Components\Forms\NewPassword;
use ADT\FancyAdmin\DI\Injects\EntityManagerInject;
use ADT\FancyAdmin\DI\Injects\OnetimeTokenQueryFactoryInject;
use ADT\FancyAdmin\DI\Injects\SecurityUserInject;
use ADT\FancyAdmin\Model\Entities\Identity;
use ADT\FancyAdmin\Model\Entities\OnetimeToken;
use ADT\FancyAdmin\UI\Components\ControlTrait;
use ADT\FancyAdmin\UI\Components\Forms\FormTrait;
use ADT\FancyAdmin\UI\RedirectAfterLoginTrait;
use ADT\Forms\Form;
use Nette\Security\AuthenticationException;
use Nette\Utils\ArrayHash;
trait NewPasswordFormTrait
{
use ControlTrait;
use RedirectAfterLoginTrait;
use SecurityUserInject;
use EntityManagerInject;
public function initForm(Form $form): void
{
$form->getElementPrototype()->class[] = 'login-form';
$form->addSection(function () use ($form) {
// $form->addText('firstName')
// ->setHtmlAttribute('placeholder', 'Jméno') // TODO translate
// ->setRequired();
//
// $form->addText('lastName')
// ->setHtmlAttribute('placeholder', 'Příjmení') // TODO translate
// ->setRequired();
//
// $form->addEmail('email')
// ->setHtmlAttribute('placeholder', 'E-mail') // TODO translate
// ->setRequired();
//
// $form->addPhoneNumber('phoneNumber', null, 'Zadejte validní telefonní číslo') // TODO trnaslate
// ->setHtmlAttribute('placeholder', 'Telefon') // TODO translate
// ->setRequired();
$form->addPassword('password')
->setHtmlAttribute('placeholder', 'fcadmin.forms.newPassword.labels.password') // TODO translate
->setRequired('fcadmin.forms.newPassword.errors.required');
$form->addPassword('passwordRepeat')
->setHtmlAttribute('placeholder', 'fcadmin.forms.newPassword.labels.passwordAgain') // TODO translate
->setRequired('fcadmin.forms.newPassword.errors.required');
}, 'inputsWrap');
$form->addSubmit('submit', 'Uložit'); // TODO translate
$form->getComponentSubmitButton('submit')->getControlPrototype()->class[] = 'btn ';
$form->getComponentSubmitButton('submit')->getControlPrototype()->class[] = 'w-100';
$form->getComponentSubmitButton('submit')->getControlPrototype()->class[] = 'btn-primary';
}
public function validateForm(array $values, Form $form): void
{
if ($values['password'] !== $values['passwordRepeat']) {
$form->getComponentTextInput('passwordRepeat')->addError('fcadmin.forms.newPassword.errors.noMatch'); // TODO
}
}
public function processForm(array $values): void
{
$this->_securityUser->logout(true);
$this->_securityUser->login($this->getEntity(), context: $this->_fancyAdmin->getContext());
$this->_securityUser->getIdentity()->setPassword($values['password']);
$this->_em->flush();
$this->redirectAfterLogin();
}
public function getEntityClass(): ?string
{
return $this->_em->findEntityClassByInterface(Identity::class);
}
}