1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Presenters; |
4
|
|
|
|
5
|
|
|
use Nette; |
6
|
|
|
use Nette\Application\UI\Form; |
7
|
|
|
use Cothema\Model as PModel; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @Secured |
11
|
|
|
* @Secured\User(loggedIn) |
12
|
|
|
* @Secured\Role(admin) |
13
|
|
|
* |
14
|
|
|
* Users Presenter |
15
|
|
|
*/ |
16
|
|
|
class UsersPresenter extends BasePresenter |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function renderChangePass() |
20
|
|
|
{ |
21
|
|
|
$navbar = []; |
22
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
23
|
|
|
$navbar[] = (object) ['name' => 'Detail']; |
24
|
|
|
$navbar[] = (object) ['name' => 'Změna hesla']; |
25
|
|
|
|
26
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function renderList() |
30
|
|
|
{ |
31
|
|
|
$navbar = []; |
32
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé']; |
33
|
|
|
|
34
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
35
|
|
|
|
36
|
|
|
$usersDao = $this->em->getRepository(PModel\User\User::getClassName()); |
37
|
|
|
$users = $usersDao->findBy(['active' => 1]); |
38
|
|
|
|
39
|
|
|
$this->template->users = $users; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function renderListUnactive() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$navbar = []; |
45
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
46
|
|
|
$navbar[] = (object) ['name' => 'Neaktivní']; |
47
|
|
|
|
48
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
49
|
|
|
|
50
|
|
|
$usersDao = $this->em->getRepository(PModel\User\User::getClassName()); |
51
|
|
|
$users = $usersDao->findBy(['active' => 0]); |
52
|
|
|
|
53
|
|
|
$this->template->users = $users; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Secured |
58
|
|
|
* @Secured\User(loggedIn) |
59
|
|
|
* @Secured\Role(usermanager) |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function renderNew() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$navbar = []; |
64
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
65
|
|
|
$navbar[] = (object) ['name' => 'Nový']; |
66
|
|
|
|
67
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function renderChange() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$navbar = []; |
73
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
74
|
|
|
$navbar[] = (object) ['name' => 'Úprava']; |
75
|
|
|
|
76
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->notYetImplemented(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function renderProfile() |
82
|
|
|
{ |
83
|
|
|
$navbar = []; |
84
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
85
|
|
|
$navbar[] = (object) ['name' => 'Profil']; |
86
|
|
|
|
87
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
88
|
|
|
|
89
|
|
|
$id = ($this->getParameter('id') !== null) ? $this->getParameter('id') : $this->getUser()->getIdentity()->id; |
90
|
|
|
|
91
|
|
|
$user = $this->em->getRepository(PModel\User\User::getClassName()); |
92
|
|
|
$profileUser = $user->find($id); |
93
|
|
|
|
94
|
|
|
$this->template->profileUser = $profileUser; |
|
|
|
|
95
|
|
|
|
96
|
|
|
$isActual = false; |
97
|
|
|
if ($this->getUser()->isLoggedIn() && $this->getUser()->getIdentity()->id |
98
|
|
|
== $profileUser->id) { |
99
|
|
|
$isActual = true; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->template->isActual = $isActual; |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function renderGroups() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$navbar = []; |
108
|
|
|
$navbar[] = (object) ['name' => 'Uživatelé', 'link' => 'Users:list']; |
109
|
|
|
$navbar[] = (object) ['name' => 'Skupiny']; |
110
|
|
|
|
111
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
112
|
|
|
|
113
|
|
|
$userGroupsDao = $this->em->getRepository(PModel\User\Group::getClassName()); |
114
|
|
|
$userGroups = $userGroupsDao->findAll(); |
115
|
|
|
|
116
|
|
|
$this->template->userGroups = $userGroups; |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @Secured |
121
|
|
|
* @Secured\User(loggedIn) |
122
|
|
|
* @Secured\Role(superadmin) |
123
|
|
|
*/ |
124
|
|
View Code Duplication |
public function renderLogActivity() |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
$navbar = []; |
127
|
|
|
$navbar[] = (object) ['link' => 'Users:list', 'name' => 'Uživatelé']; |
128
|
|
|
$navbar[] = (object) ['name' => 'Sledování přihlášení']; |
129
|
|
|
|
130
|
|
|
$this->template->navbar = $navbar; |
|
|
|
|
131
|
|
|
|
132
|
|
|
$activityDao = $this->em->getRepository(PModel\User\LogActivity::getClassName()); |
133
|
|
|
$activity = $activityDao->findBy([], ['id' => 'DESC'], 30); |
134
|
|
|
|
135
|
|
|
$this->template->activity = $activity; |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
protected function createComponentChangePasswordForm() |
139
|
|
|
{ |
140
|
|
|
$form = new Nette\Application\UI\Form; |
141
|
|
|
$form->addPassword('oldpassw', 'Staré heslo:') |
142
|
|
|
->setRequired('Prosím, zadejte své staré heslo.') |
|
|
|
|
143
|
|
|
->getControlPrototype()->class('form-control'); |
144
|
|
|
|
145
|
|
|
$form->addPassword('newpassw', 'Nové heslo:') |
146
|
|
|
->setRequired('Prosím, zadejte své nové heslo.') |
|
|
|
|
147
|
|
|
->getControlPrototype()->class('form-control'); |
148
|
|
|
|
149
|
|
|
$form->addPassword('newpassw2', 'Nové heslo (znovu):') |
150
|
|
|
->setRequired('Prosím, zadejte své nové heslo pro kontrolu.') |
|
|
|
|
151
|
|
|
->addRule( |
152
|
|
|
Form::EQUAL, |
153
|
|
|
"Zadaná nová hesla se neshodují.", |
154
|
|
|
$form["newpassw"] |
155
|
|
|
) |
156
|
|
|
->getControlPrototype()->class('form-control'); |
157
|
|
|
|
158
|
|
|
$form->addSubmit('send', 'Změnit heslo') |
159
|
|
|
->getControlPrototype()->class('btn btn-success'); |
160
|
|
|
|
161
|
|
|
$form->onSuccess[] = [$this, 'changePasswordFormSucceeded']; |
162
|
|
|
return $form; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
protected function createComponentChangeProfileForm() |
166
|
|
|
{ |
167
|
|
|
$userDao = $this->em->getRepository(PModel\User\User::getClassName()); |
168
|
|
|
$user = $userDao->find($this->getUser()->id); |
169
|
|
|
|
170
|
|
|
$form = new Nette\Application\UI\Form; |
171
|
|
|
$form->addText('firstname', 'Jméno:') |
172
|
|
|
->setRequired('Prosím, zadejte své své jméno.') |
|
|
|
|
173
|
|
|
->setDefaultValue($user->firstName) |
174
|
|
|
->getControlPrototype()->class('form-control'); |
175
|
|
|
|
176
|
|
|
$form->addText('lastname', 'Příjmení:') |
177
|
|
|
->setRequired('Prosím, zadejte své nové příjmení.') |
|
|
|
|
178
|
|
|
->setDefaultValue($user->lastName) |
179
|
|
|
->getControlPrototype()->class('form-control'); |
180
|
|
|
|
181
|
|
|
$form->addText('email', 'Email:') |
182
|
|
|
->setRequired('Prosím, zadejte svou emailovou adesu.') |
|
|
|
|
183
|
|
|
->setDefaultValue($user->email) |
184
|
|
|
->getControlPrototype()->class('form-control'); |
185
|
|
|
|
186
|
|
|
$form->addSubmit('send', 'Uložit změny') |
187
|
|
|
->getControlPrototype()->class('btn btn-success'); |
188
|
|
|
|
189
|
|
|
$form->onSuccess[] = [$this, 'changeProfileFormSucceeded']; |
190
|
|
|
return $form; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function createComponentUsersNewForm() |
194
|
|
|
{ |
195
|
|
|
$form = new Form; |
196
|
|
|
|
197
|
|
|
$form->addText('login', 'Přihlašovací jméno:') |
198
|
|
|
->setRequired('Prosím, zadejte přihlašovací jméno.') |
|
|
|
|
199
|
|
|
->getControlPrototype()->class('form-control'); |
200
|
|
|
|
201
|
|
|
$form->addText('firstname', 'Jméno:') |
202
|
|
|
->setRequired('Prosím, zadejte jméno.') |
|
|
|
|
203
|
|
|
->getControlPrototype()->class('form-control'); |
204
|
|
|
|
205
|
|
|
$form->addText('lastname', 'Příjmení:') |
206
|
|
|
->setRequired('Prosím, zadejte příjmení.') |
|
|
|
|
207
|
|
|
->getControlPrototype()->class('form-control'); |
208
|
|
|
|
209
|
|
|
$form->addText('email', 'Email:') |
210
|
|
|
->setRequired('Prosím, zadejte emailovou adesu.') |
|
|
|
|
211
|
|
|
->getControlPrototype()->class('form-control mediumwidth'); |
212
|
|
|
|
213
|
|
|
$form->addPassword('password', 'Heslo:') |
214
|
|
|
->setRequired('Prosím, zadejte heslo.') |
|
|
|
|
215
|
|
|
->getControlPrototype()->class('form-control mediumwidth'); |
216
|
|
|
|
217
|
|
|
$form->addPassword('passwordValid', 'Heslo znovu:') |
218
|
|
|
->setRequired('Prosím, zadejte heslo pro kontrolu.') |
|
|
|
|
219
|
|
|
->getControlPrototype()->class('form-control mediumwidth'); |
220
|
|
|
|
221
|
|
|
$form->addSubmit('send', 'Vytvořit uživatelský profil') |
222
|
|
|
->getControlPrototype()->class('btn btn-success'); |
223
|
|
|
|
224
|
|
|
$form->onSuccess[] = [$this, 'usersNewFormSucceeded']; |
225
|
|
|
return $form; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function createComponentUsersChangeForm() |
229
|
|
|
{ |
230
|
|
|
$userDao = $this->em->getRepository(PModel\User\User::getClassName()); |
231
|
|
|
$user = $userDao->find($this->getUser()->id); |
232
|
|
|
|
233
|
|
|
$form = new Form; |
234
|
|
|
|
235
|
|
|
$form->addText('login', 'Přihlašovací jméno:') |
236
|
|
|
->setRequired('Prosím, zadejte přihlašovací jméno.') |
|
|
|
|
237
|
|
|
->setDisabled() |
238
|
|
|
->setValue($user->username) |
239
|
|
|
->getControlPrototype()->class('form-control'); |
240
|
|
|
|
241
|
|
|
$form->addText('firstname', 'Jméno:') |
242
|
|
|
->setRequired('Prosím, zadejte jméno.') |
|
|
|
|
243
|
|
|
->setDefaultValue($user->firstName) |
244
|
|
|
->getControlPrototype()->class('form-control'); |
245
|
|
|
|
246
|
|
|
$form->addText('lastname', 'Příjmení:') |
247
|
|
|
->setRequired('Prosím, zadejte příjmení.') |
|
|
|
|
248
|
|
|
->setDefaultValue($user->lastName) |
249
|
|
|
->getControlPrototype()->class('form-control'); |
250
|
|
|
|
251
|
|
|
$form->addText('email', 'Email:') |
252
|
|
|
->setRequired('Prosím, zadejte emailovou adesu.') |
|
|
|
|
253
|
|
|
->setDefaultValue($user->email) |
254
|
|
|
->getControlPrototype()->class('form-control mediumwidth'); |
255
|
|
|
|
256
|
|
|
$form->addSubmit('send', 'Upravit uživatelský profil') |
257
|
|
|
->getControlPrototype()->class('btn btn-warning'); |
258
|
|
|
|
259
|
|
|
$form->onSuccess[] = [$this, 'usersNewFormSucceeded']; |
260
|
|
|
return $form; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function usersNewFormSucceeded() |
264
|
|
|
{ |
265
|
|
|
} |
266
|
|
|
|
267
|
|
View Code Duplication |
public function handleActive($id) |
|
|
|
|
268
|
|
|
{ |
269
|
|
|
$this->setActiveStatus($id, true); |
270
|
|
|
|
271
|
|
|
$this->flashMessage( |
272
|
|
|
'Uživatel s ID '.$id.' byl úspěšně aktivován.', |
273
|
|
|
'success' |
274
|
|
|
); |
275
|
|
|
$this->redirect('this'); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
View Code Duplication |
public function handleDeactive($id) |
|
|
|
|
279
|
|
|
{ |
280
|
|
|
$this->setActiveStatus($id, false); |
281
|
|
|
|
282
|
|
|
$this->flashMessage( |
283
|
|
|
'Uživatel s ID '.$id.' byl úspěšně deaktivován.', |
284
|
|
|
'success' |
285
|
|
|
); |
286
|
|
|
$this->redirect('this'); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @param boolean $status |
291
|
|
|
*/ |
292
|
|
|
private function setActiveStatus($id, $status) |
293
|
|
|
{ |
294
|
|
|
$userDao = $this->em->getRepository(PModel\User\User::getClassName()); |
295
|
|
|
$user = $userDao->find($id); |
296
|
|
|
$user->active = (bool) $status; |
297
|
|
|
|
298
|
|
|
$this->em->persist($user); |
299
|
|
|
$this->em->flush(); |
300
|
|
|
|
301
|
|
|
return true; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function changeProfileFormSucceeded($form) |
305
|
|
|
{ |
306
|
|
|
$values = $form->getValues(true); |
307
|
|
|
|
308
|
|
|
$userDao = $this->em->getRepository(PModel\User\User::getClassName()); |
309
|
|
|
$user = $userDao->find($this->getUser()->id); |
310
|
|
|
$user->firstName = $values['firstname']; |
311
|
|
|
$user->lastName = $values['lastname']; |
312
|
|
|
$user->email = $values['email']; |
313
|
|
|
|
314
|
|
|
$this->em->persist($user); |
315
|
|
|
$this->em->flush(); |
316
|
|
|
|
317
|
|
|
$this->flashMessage('Údaje o uživateli byly úspěšně uloženy.', 'success'); |
318
|
|
|
$this->redirect('Users:profile'); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
public function changePasswordFormSucceeded($form) |
322
|
|
|
{ |
323
|
|
|
$values = $form->getValues(); |
324
|
|
|
$userId = $this->getUser()->id; |
325
|
|
|
|
326
|
|
|
$fOldPass = $values["oldpassw"]; |
327
|
|
|
$fNewPass = $values["newpassw"]; |
328
|
|
|
|
329
|
|
|
try { |
330
|
|
|
$this->getUser()->getAuthenticator()->changePassword( |
331
|
|
|
$userId, |
332
|
|
|
$fOldPass, |
333
|
|
|
$fNewPass |
334
|
|
|
); |
335
|
|
|
|
336
|
|
|
$this->flashMessage('Vaše heslo bylo úspěšně změněno.', 'success'); |
337
|
|
|
$this->redirect('Users:profile'); |
338
|
|
|
} catch (Nette\Security\AuthenticationException $e) { |
339
|
|
|
$form->addError('Zadané staré heslo není správné.'); |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.