1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alvo\User; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\Di\InjectionAwareTrait; |
9
|
|
|
use \Alvo\User\HTMLForm\UserLoginForm; |
10
|
|
|
use \Alvo\User\HTMLForm\CreateUserForm; |
11
|
|
|
use \Alvo\User\HTMLForm\UpdateUserForm; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A controller class. |
15
|
|
|
*/ |
16
|
|
|
class UserController implements InjectionAwareInterface |
17
|
|
|
{ |
18
|
|
|
use InjectionAwareTrait; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Init module |
24
|
|
|
*/ |
25
|
1 |
View Code Duplication |
public function init() |
|
|
|
|
26
|
|
|
{ |
27
|
1 |
|
$this->session = $this->di->get("session"); |
|
|
|
|
28
|
1 |
|
$this->response = $this->di->get("response"); |
|
|
|
|
29
|
1 |
|
$this->user = $this->di->get("user"); |
|
|
|
|
30
|
1 |
|
$this->view = $this->di->get("view"); |
|
|
|
|
31
|
1 |
|
$this->pageRender = $this->di->get("pageRender"); |
|
|
|
|
32
|
1 |
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Description. |
38
|
|
|
* |
39
|
|
|
* @param datatype $variable Description |
|
|
|
|
40
|
|
|
* |
41
|
|
|
* @throws Exception |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function getIndex() |
46
|
|
|
{ |
47
|
|
|
if (!$this->user->isLoggedIn()) { |
48
|
|
|
$this->response->redirect('user/login'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$title = "Profile"; |
52
|
|
|
|
53
|
|
|
$form = new UpdateUserForm($this->di); |
54
|
|
|
$form->check(); |
55
|
|
|
|
56
|
|
|
$user = $this->user->find("id", $this->session->get("userId")); |
57
|
|
|
// debug($user); |
58
|
|
|
|
59
|
|
|
$data = $this->user->getUser('email', $user->email); |
60
|
|
|
|
61
|
|
|
$this->view->add("user/profile", ["user" => $data, "form" => $form->getHTML()]); |
62
|
|
|
|
63
|
|
|
$this->pageRender->renderPage(["title" => $title]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Description. |
70
|
|
|
* |
71
|
|
|
* @param datatype $variable Description |
72
|
|
|
* |
73
|
|
|
* @throws Exception |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function getPostLogin() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
if ($this->user->isLoggedIn()) { |
80
|
|
|
$this->response->redirect("user"); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$title = "A login page"; |
84
|
|
|
$view = $this->di->get("view"); |
85
|
|
|
$pageRender = $this->di->get("pageRender"); |
86
|
|
|
$form = new UserLoginForm($this->di); |
87
|
|
|
|
88
|
|
|
$form->check(); |
89
|
|
|
|
90
|
|
|
$data = [ |
91
|
|
|
"content" => $form->getHTML(), |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
// var_dump($form); |
95
|
|
|
// exit; |
96
|
|
|
// $this->utils->login() |
97
|
|
|
|
98
|
|
|
// $response->redirect('user'); |
99
|
|
|
|
100
|
|
|
$view->add("default2/article", $data); |
101
|
|
|
|
102
|
|
|
$pageRender->renderPage(["title" => $title]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Description. |
109
|
|
|
* |
110
|
|
|
* @param datatype $variable Description |
111
|
|
|
* |
112
|
|
|
* @throws Exception |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function getPostCreateUser() |
117
|
|
|
{ |
118
|
|
|
$title = "A create user page"; |
119
|
|
|
$view = $this->di->get("view"); |
120
|
|
|
$pageRender = $this->di->get("pageRender"); |
121
|
|
|
$form = new CreateUserForm($this->di); |
122
|
|
|
|
123
|
|
|
$form->check(); |
124
|
|
|
|
125
|
|
|
$data = [ |
126
|
|
|
"content" => $form->getHTML(), |
127
|
|
|
]; |
128
|
|
|
|
129
|
|
|
$view->add("default2/article", $data); |
130
|
|
|
|
131
|
|
|
$pageRender->renderPage(["title" => $title]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function logout() |
137
|
|
|
{ |
138
|
|
|
$this->user->logout(); |
139
|
|
|
$this->response->redirect("user/login"); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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.