-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignPresenterTrait.php
More file actions
109 lines (90 loc) · 2.84 KB
/
Copy pathSignPresenterTrait.php
File metadata and controls
109 lines (90 loc) · 2.84 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace ADT\FancyAdmin\UI\Presenters\Sign;
use ADT\FancyAdmin\DI\Injects\AuthenticatorInject;
use ADT\FancyAdmin\DI\Injects\EntityManagerInject;
use ADT\FancyAdmin\DI\Injects\FancyAdminInject;
use ADT\FancyAdmin\DI\Injects\SecurityUserInject;
use ADT\FancyAdmin\Model\Entities\Identity;
use ADT\FancyAdmin\UI\Components\Forms\LostPassword\LostPasswordForm;
use ADT\FancyAdmin\UI\Components\Forms\LostPassword\LostPasswordFormFactory;
use ADT\FancyAdmin\UI\Components\Forms\NewPassword\NewPasswordForm;
use ADT\FancyAdmin\UI\Components\Forms\NewPassword\NewPasswordFormFactory;
use ADT\FancyAdmin\UI\Components\Forms\SignIn\SignInForm;
use ADT\FancyAdmin\UI\Components\Forms\SignIn\SignInFormFactory;
use ADT\FancyAdmin\UI\Presenters\PresenterTrait;
use ADT\FancyAdmin\UI\RedirectAfterLoginTrait;
use Nette\Application\Attributes\Persistent;
use Nette\Security\AuthenticationException;
trait SignPresenterTrait
{
use PresenterTrait;
use RedirectAfterLoginTrait;
use EntityManagerInject;
use FancyAdminInject;
use SecurityUserInject;
use AuthenticatorInject;
#[Persistent]
public ?string $token = null;
protected Identity $identity;
public function actionIn(?string $errorMsg): void
{
if ($this->getUser()->isLoggedIn()) {
$this->redirectAfterLogin();
}
if ($errorMsg) {
$this->flashMessageError($errorMsg);
}
if ($this->getParameter('fraudDetected')) {
$this->flashMessageError('_fcadmin.modules.web.presenters.sign.flashFraud');
}
}
public function actionOut(): never
{
if ($this->getUser()->isLoggedIn()) {
$this->getUser()->logout(true);
}
$this->redirect('in');
}
public function actionOutAll(): never
{
if ($this->getUser()->isLoggedIn()) {
$this->_authenticator->clearIdentity(
$this->getUser()->getIdentity()->getAuthObjectId()
);
$this->getUser()->logout(true);
}
$this->redirect('in');
}
public function actionNewPassword(string $token): void
{
try {
$this->identity = $this->_authenticator->authenticate($token);
} catch(AuthenticationException) {
$this->flashMessageError('Odkaz již není platný. Pro vygenerováno nového odešlete znovu formulář.'); // TODO translate
$this->redirect(':Portal:Sign:lostPassword');
}
}
public function actionPasswordSet(): void
{
$this->template->canContinue = $this->getUser()->isLoggedIn();
}
public function handleContinue(): void
{
$this->redirectAfterLogin();
}
public function actionLostPassword(): void
{
}
public function createComponentSignInForm(SignInFormFactory $factory): SignInForm
{
return $factory->create();
}
public function createComponentLostPasswordForm(LostPasswordFormFactory $factory): LostPasswordForm
{
return $factory->create();
}
public function createComponentNewPasswordForm(NewPasswordFormFactory $factory): NewPasswordForm
{
return $factory->create()->setEntity($this->identity);
}
}