1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment; |
4
|
|
|
|
5
|
|
|
// ANAX |
6
|
|
|
use \Anax\Configure\ConfigureInterface; |
7
|
|
|
use \Anax\Configure\ConfigureTrait; |
8
|
|
|
use \Anax\DI\InjectionAwareInterface; |
9
|
|
|
use \Anax\DI\InjectionAwareTrait; |
10
|
|
|
|
11
|
|
|
// HTMLforms |
12
|
|
|
use \Nicklas\Comment\HTMLForm\User\UserLoginForm; |
13
|
|
|
use \Nicklas\Comment\HTMLForm\User\CreateUserForm; |
14
|
|
|
use \Nicklas\Comment\HTMLForm\User\UserResetForm; |
15
|
|
|
|
16
|
|
|
// MODULES |
17
|
|
|
use \Nicklas\Comment\Modules\User; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A controller class. |
21
|
|
|
*/ |
22
|
|
|
class UserController implements |
23
|
|
|
ConfigureInterface, |
24
|
|
|
InjectionAwareInterface |
25
|
|
|
{ |
26
|
|
|
use ConfigureTrait, InjectionAwareTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Logout user by setting "user" == null in session. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function logout() |
34
|
|
|
{ |
35
|
|
|
$this->di->get('session')->set("user", null); |
36
|
|
|
$this->di->get("response")->redirect("user/login"); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* check if user is logged in |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
2 |
|
public function checkIsLogin() |
46
|
|
|
{ |
47
|
2 |
View Code Duplication |
if (!$this->di->get("session")->has("user")) { |
|
|
|
|
48
|
|
|
$views = [ |
49
|
1 |
|
["user/fail/fail", [], "main"] |
50
|
1 |
|
]; |
51
|
1 |
|
$this->di->get("pageRenderComment")->renderPage([ |
52
|
1 |
|
"views" => $views, |
53
|
|
|
"title" => "Not logged in" |
54
|
1 |
|
]); |
55
|
1 |
|
} |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Description. |
63
|
|
|
* |
64
|
|
|
* @param datatype $variable Description |
|
|
|
|
65
|
|
|
* |
66
|
|
|
* @throws Exception |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
1 |
View Code Duplication |
public function getPostLogin() |
|
|
|
|
71
|
|
|
{ |
72
|
1 |
|
$form = new UserLoginForm($this->di); |
73
|
1 |
|
$form->check(); |
74
|
|
|
|
75
|
|
|
$views = [ |
76
|
1 |
|
["user/pre/login", ["form" => $form->getHTML()], "main"] |
77
|
1 |
|
]; |
78
|
|
|
|
79
|
1 |
|
$this->di->get("pageRenderComment")->renderPage([ |
80
|
1 |
|
"views" => $views, |
81
|
|
|
"title" => "Login" |
82
|
1 |
|
]); |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Description. |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
public function getPostReset() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$form = new UserResetForm($this->di); |
93
|
|
|
$form->check(); |
94
|
|
|
|
95
|
|
|
$views = [ |
96
|
|
|
["user/pre/reset", ["form" => $form->getHTML()], "main"] |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$this->di->get("pageRenderComment")->renderPage([ |
100
|
|
|
"views" => $views, |
101
|
|
|
"title" => "Reset password" |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Description. |
109
|
|
|
* |
110
|
|
|
* @param datatype $variable Description |
|
|
|
|
111
|
|
|
* |
112
|
|
|
* @throws Exception |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
1 |
View Code Duplication |
public function getPostCreateUser() |
|
|
|
|
117
|
|
|
{ |
118
|
1 |
|
$form = new CreateUserForm($this->di); |
119
|
1 |
|
$form->check(); |
120
|
|
|
|
121
|
|
|
$views = [ |
122
|
1 |
|
["user/pre/create", ["form" => $form->getHTML()], "main"] |
123
|
1 |
|
]; |
124
|
|
|
|
125
|
1 |
|
$this->di->get("pageRenderComment")->renderPage([ |
126
|
1 |
|
"views" => $views, |
127
|
|
|
"title" => "Create User" |
128
|
1 |
|
]); |
129
|
1 |
|
} |
130
|
|
|
} |
131
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.