|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use Skautis; |
|
6
|
|
|
use SkautisAuth; |
|
7
|
|
|
use App\Services\SkautIS\AuthService; |
|
8
|
|
|
use App\Services\SkautIS\UserService; |
|
9
|
|
|
use Tracy\Debugger; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* SkautIS Auth presenters. |
|
13
|
|
|
*/ |
|
14
|
|
|
class AuthPresenter extends BasePresenter |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var AuthService |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $authService; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var UserService |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $userService; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var User |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $user; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param AuthService $authService |
|
34
|
|
|
* @param UserService $userService |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
AuthService $authService, |
|
38
|
|
|
UserService $userService |
|
39
|
|
|
) { |
|
40
|
|
|
$this->setAuthService($authService); |
|
41
|
|
|
$this->setUserService($userService); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function startup() |
|
48
|
|
|
{ |
|
49
|
|
|
parent::startup(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $id |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
public function actionLogin($id) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->{$id . 'Login'}(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $id |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function actionLogout($id) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->{$id . 'Logout'}(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $id |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function actionSkautis($id) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->{'handleSkautis' . $id}(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Redirects to login page |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $backlink |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function skautisLogin($backlink = null) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->redirectUrl($this->getAuthService()->getLoginUrl($backlink)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Handle log out from SkautIS |
|
92
|
|
|
* SkautIS redirects to this action after log out |
|
93
|
|
|
* |
|
94
|
|
|
* @param void |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function skautisLogout() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->redirectUrl($this->getAuthService()->getLogoutUrl()); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Handle SkautIS login process |
|
104
|
|
|
* |
|
105
|
|
|
* @param string $ReturnUrl |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function handleSkautisLogin($ReturnUrl = NULL) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
|
|
$post = $this->getHttpRequest()->post; |
|
|
|
|
|
|
111
|
|
|
//$post = $this->router->getPost(); |
|
112
|
|
|
// if token is not set - get out from here - must log in |
|
113
|
|
|
if (!isset($post['skautIS_Token'])) { |
|
114
|
|
|
$this->redirect(":Login:"); |
|
115
|
|
|
} |
|
116
|
|
|
//Debugger::log("AuthP: ".$post['skautIS_Token']." / ". $post['skautIS_IDRole'] . " / " . $post['skautIS_IDUnit'], "auth"); |
|
117
|
|
|
try { |
|
118
|
|
|
$this->getAuthService()->setInit($post); |
|
119
|
|
|
//$this->container->getService('authService')->setInit($post); |
|
120
|
|
|
|
|
121
|
|
|
if (!$this->getUserService()->isLoggedIn()) { |
|
122
|
|
|
//if (!$this->container->getService('userService')->isLoggedIn()) { |
|
123
|
|
|
throw new \Skautis\Wsdl\AuthenticationException("Nemáte platné přihlášení do skautISu"); |
|
124
|
|
|
} |
|
125
|
|
|
$me = $this->getUserService()->getPersonalDetail(); |
|
126
|
|
|
//$me = $this->container->getService('userService')->getPersonalDetail(); |
|
127
|
|
|
|
|
128
|
|
|
$this->getUser()->setExpiration('+ 29 minutes'); // nastavíme expiraci |
|
129
|
|
|
$this->getUser()->setAuthenticator(new SkautisAuth\SkautisAuthenticator()); |
|
130
|
|
|
$this->getUser()->login($me); |
|
131
|
|
|
|
|
132
|
|
|
if (isset($ReturnUrl)) { |
|
133
|
|
|
$this->context->application->restoreRequest($ReturnUrl); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
} catch (\Skautis\Wsdl\AuthenticationException $e) { |
|
136
|
|
|
$this->flashMessage($e->getMessage(), "danger"); |
|
137
|
|
|
$this->redirect(":Auth:Login"); |
|
138
|
|
|
} |
|
139
|
|
|
$this->presenter->redirect(':Registration:'); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Log out from SkautIS |
|
144
|
|
|
* |
|
145
|
|
|
* @param void |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function handleSkautisLogout() |
|
149
|
|
|
{ |
|
150
|
|
|
$this->getUserService()->logout(TRUE); |
|
|
|
|
|
|
151
|
|
|
$this->getUserService()->resetLoginData(); |
|
152
|
|
|
$this->presenter->flashMessage("Byl jsi úspěšně odhlášen ze SkautISu."); |
|
153
|
|
|
/* |
|
154
|
|
|
if ($this->request->post['skautIS_Logout']) { |
|
155
|
|
|
$this->presenter->flashMessage("Byl jsi úspěšně odhlášen ze SkautISu."); |
|
156
|
|
|
} else { |
|
157
|
|
|
$this->presenter->flashMessage("Odhlášení ze skautISu se nezdařilo", "danger"); |
|
158
|
|
|
} |
|
159
|
|
|
*/ |
|
160
|
|
|
$this->redirect(":Login:"); |
|
161
|
|
|
//$this->redirectUrl($this->service->getLogoutUrl()); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return AuthService |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function getAuthService() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->authService; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @param AuthService $service |
|
174
|
|
|
* @return $this |
|
175
|
|
|
*/ |
|
176
|
|
|
protected function setAuthService(AuthService $service) |
|
177
|
|
|
{ |
|
178
|
|
|
$this->authService = $service; |
|
179
|
|
|
|
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return UserService |
|
185
|
|
|
*/ |
|
186
|
|
|
protected function getUserService() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->userService; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param UserService $service |
|
193
|
|
|
* @return $this |
|
194
|
|
|
*/ |
|
195
|
|
|
protected function setUserService(UserService $service) |
|
196
|
|
|
{ |
|
197
|
|
|
$this->userService = $service; |
|
198
|
|
|
|
|
199
|
|
|
return $this; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
|
This check marks parameter names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.