1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\User; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\Di\InjectionAwareTrait; |
9
|
|
|
use \Anax\User\HTMLForm\UserLoginForm; |
10
|
|
|
use \Anax\User\HTMLForm\CreateUserForm; |
11
|
|
|
use \Anax\User\HTMLForm\EditUserForm; |
12
|
|
|
use \Anax\User\HTMLForm\DeleteUserForm; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A controller class. |
16
|
|
|
*/ |
17
|
|
|
class UserController implements |
18
|
|
|
ConfigureInterface, |
19
|
|
|
InjectionAwareInterface |
20
|
|
|
{ |
21
|
|
|
use ConfigureTrait, |
22
|
|
|
InjectionAwareTrait; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var $data description |
28
|
|
|
*/ |
29
|
|
|
//private $data; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Description. |
35
|
|
|
* |
36
|
|
|
* @param datatype $variable Description |
37
|
|
|
* |
38
|
|
|
* @throws Exception |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
// public function getIndex() |
43
|
|
|
// { |
44
|
|
|
// $title = "A index page"; |
45
|
|
|
// $view = $this->di->get("view"); |
46
|
|
|
// $pageRender = $this->di->get("pageRender"); |
47
|
|
|
// |
48
|
|
|
// $data = [ |
49
|
|
|
// "content" => "An index page", |
50
|
|
|
// ]; |
51
|
|
|
// |
52
|
|
|
// $view->add("default2/article", $data); |
53
|
|
|
// |
54
|
|
|
// $pageRender->renderPage(["title" => $title]); |
55
|
|
|
// } |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Description. |
61
|
|
|
* |
62
|
|
|
* @param datatype $variable Description |
|
|
|
|
63
|
|
|
* |
64
|
|
|
* @throws Exception |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function getPostLogin() |
69
|
|
|
{ |
70
|
|
|
$title = "A login page"; |
71
|
|
|
$view = $this->di->get("view"); |
72
|
|
|
$pageRender = $this->di->get("pageRender"); |
73
|
|
|
$form = new UserLoginForm($this->di); |
74
|
|
|
|
75
|
|
|
$form->check(); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$data = [ |
79
|
|
|
"content" => $form->getHTML(), |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$view->add("default2/article", $data); |
83
|
|
|
|
84
|
|
|
$pageRender->renderPage(["title" => $title]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Description. |
91
|
|
|
* |
92
|
|
|
* @param datatype $variable Description |
|
|
|
|
93
|
|
|
* |
94
|
|
|
* @throws Exception |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function getPostCreateUser() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$title = "A create user page"; |
101
|
|
|
$view = $this->di->get("view"); |
102
|
|
|
$pageRender = $this->di->get("pageRender"); |
103
|
|
|
$form = new CreateUserForm($this->di); |
104
|
|
|
|
105
|
|
|
$form->check(); |
106
|
|
|
|
107
|
|
|
$data = [ |
108
|
|
|
"content" => $form->getHTML(), |
109
|
|
|
]; |
110
|
|
|
|
111
|
|
|
$view->add("default2/article", $data); |
112
|
|
|
|
113
|
|
|
$pageRender->renderPage(["title" => $title]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Description. |
118
|
|
|
* |
119
|
|
|
* @param datatype $variable Description |
|
|
|
|
120
|
|
|
* |
121
|
|
|
* @throws Exception |
122
|
|
|
* |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
public function editAllUsers() |
126
|
|
|
{ |
127
|
|
|
$acronym = $this->di->session->get("user"); |
128
|
|
|
$role = $this->di->get("commentController")->getRole($acronym); |
129
|
|
|
if ($role != 10) { |
130
|
|
|
echo "Du har ej tillgång till sidan."; |
131
|
|
|
return false; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$title = "An edit all users page"; |
135
|
|
|
$view = $this->di->get("view"); |
136
|
|
|
$pageRender = $this->di->get("pageRender"); |
137
|
|
|
$form = new DeleteUserForm($this->di); |
138
|
|
|
|
139
|
|
|
$form->check(); |
140
|
|
|
|
141
|
|
|
$data = [ |
142
|
|
|
"content" => $form->getHTML(), |
143
|
|
|
]; |
144
|
|
|
|
145
|
|
|
$view->add("default2/article", $data); |
146
|
|
|
|
147
|
|
|
$pageRender->renderPage(["title" => $title]); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Description. |
152
|
|
|
* |
153
|
|
|
* @param datatype $variable Description |
|
|
|
|
154
|
|
|
* |
155
|
|
|
* @throws Exception |
156
|
|
|
* |
157
|
|
|
* @return void |
158
|
|
|
*/ |
159
|
|
|
public function showProfile() |
160
|
|
|
{ |
161
|
|
|
$acronym = $this->di->session->get("user"); |
162
|
|
|
$user = new User(); |
163
|
|
|
$user->setDb($this->di->get("db")); |
164
|
|
|
$user = $user->find("acronym", $acronym); |
165
|
|
|
|
166
|
|
|
if (isset($user->email)) { |
167
|
|
|
$this->editUser($user->id); |
168
|
|
|
} |
169
|
|
|
// if no user is logged in: |
170
|
|
|
|
171
|
|
|
$val = $this->di->get("url")->createRelative("user/login"); |
172
|
|
|
$view = $this->di->get("view"); |
173
|
|
|
$pageRender = $this->di->get("pageRender"); |
174
|
|
|
$data = [ |
175
|
|
|
"content" => "<h2><a href='$val'>Logga in</a> för att se din profil.</h2>" |
176
|
|
|
]; |
177
|
|
|
|
178
|
|
|
$view->add("default2/article", $data); |
179
|
|
|
$pageRender->renderPage(["title" => "Ej tillgång"]); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Description. |
184
|
|
|
* |
185
|
|
|
* @param datatype $variable Description |
|
|
|
|
186
|
|
|
* |
187
|
|
|
* @throws Exception |
188
|
|
|
* |
189
|
|
|
* @return void |
190
|
|
|
*/ |
191
|
|
|
public function editUser($id) |
192
|
|
|
{ |
193
|
|
|
$title = "Redigera användare"; |
194
|
|
|
$view = $this->di->get("view"); |
195
|
|
|
$pageRender = $this->di->get("pageRender"); |
196
|
|
|
|
197
|
|
|
$user = new User; |
198
|
|
|
$user->setDb($this->di->get("db")); |
199
|
|
|
$user = $user->find("id", $id); |
200
|
|
|
|
201
|
|
|
$data = [ |
202
|
|
|
"title" => $title, |
203
|
|
|
"email" => $user->email, |
204
|
|
|
"acronym" => $user->acronym, |
205
|
|
|
"gravatar" => $user->gravatar, |
206
|
|
|
"role" => $user->role, |
207
|
|
|
]; |
208
|
|
|
|
209
|
|
|
$form = new EditUserForm($this->di, $user->acronym); |
210
|
|
|
$form->check(); |
211
|
|
|
|
212
|
|
|
$formdata = [ |
213
|
|
|
"content" => $form->getHTML(), |
214
|
|
|
]; |
215
|
|
|
|
216
|
|
|
$view->add("take1/profile", $data); |
217
|
|
|
$view->add("default2/article", $formdata); |
218
|
|
|
|
219
|
|
|
$pageRender->renderPage(["title" => $title]); |
220
|
|
|
return true; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Description. |
225
|
|
|
* |
226
|
|
|
* @param datatype $variable Description |
|
|
|
|
227
|
|
|
* |
228
|
|
|
* @throws Exception |
229
|
|
|
* |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
|
|
public function editOneUser($id) |
233
|
|
|
{ |
234
|
|
|
$title = "Redigera en användare"; |
235
|
|
|
$view = $this->di->get("view"); |
236
|
|
|
$pageRender = $this->di->get("pageRender"); |
237
|
|
|
|
238
|
|
|
$user = new User; |
239
|
|
|
$user->setDb($this->di->get("db")); |
240
|
|
|
$user = $user->find("id", $id); |
241
|
|
|
|
242
|
|
|
// $data = [ |
243
|
|
|
// "title" => $title, |
244
|
|
|
// "email" => $user->email, |
245
|
|
|
// "acronym" => $user->acronym, |
246
|
|
|
// "gravatar" => $user->gravatar, |
247
|
|
|
// ]; |
248
|
|
|
|
249
|
|
|
$form = new EditUserForm($this->di, $user->acronym); |
250
|
|
|
$form->check(); |
251
|
|
|
|
252
|
|
|
$formdata = [ |
253
|
|
|
"content" => $form->getHTML(), |
254
|
|
|
]; |
255
|
|
|
|
256
|
|
|
$view->add("default2/article", $formdata); |
257
|
|
|
|
258
|
|
|
$pageRender->renderPage(["title" => $title]); |
259
|
|
|
return true; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.