Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
41.94% |
39 / 93 |
|
32.14% |
9 / 28 |
CRAP | |
0.00% |
0 / 1 |
AccountController | |
41.94% |
39 / 93 |
|
32.14% |
9 / 28 |
404.97 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
index | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
login_get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
login_post | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
5.03 | |||
logout | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
signup_step1_get | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
signup_step1_post | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
signup_notify | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
signup_step2_get | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
signup_step2_post | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
user | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
user_edit_get | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
user_edit_post | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
user_api_get | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
user_api_post | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
user_password_get | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
user_password_post | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
user_email_get | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
user_email_post | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
user_plugin_get_core | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
user_plugin_post_core | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
user_plugin_register_get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user_plugin_register_post | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user_plugin_update_get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user_plugin_update_post | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user_audit_logs_top | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
user_audit_logs_page | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
user_audit_logs_download | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Controllers\Page; |
6 | |
7 | use PeServer\App\Controllers\Page\PageControllerBase; |
8 | use PeServer\App\Models\Data\SessionAccount; |
9 | use PeServer\App\Models\Domain\Page\Account\AccountApiLogic; |
10 | use PeServer\App\Models\Domain\Page\Account\AccountLoginLogic; |
11 | use PeServer\App\Models\Domain\Page\Account\AccountLogoutLogic; |
12 | use PeServer\App\Models\Domain\Page\Account\AccountSignupNotifyLogic; |
13 | use PeServer\App\Models\Domain\Page\Account\AccountSignupStep1Logic; |
14 | use PeServer\App\Models\Domain\Page\Account\AccountSignupStep2Logic; |
15 | use PeServer\App\Models\Domain\Page\Account\AccountUserApiLogic; |
16 | use PeServer\App\Models\Domain\Page\Account\AccountUserAuditLogDownloadLogic; |
17 | use PeServer\App\Models\Domain\Page\Account\AccountUserAuditLogLogic; |
18 | use PeServer\App\Models\Domain\Page\Account\AccountUserEditLogic; |
19 | use PeServer\App\Models\Domain\Page\Account\AccountUserEmailLogic; |
20 | use PeServer\App\Models\Domain\Page\Account\AccountUserLogic; |
21 | use PeServer\App\Models\Domain\Page\Account\AccountUserPasswordLogic; |
22 | use PeServer\App\Models\Domain\Page\Account\AccountUserPluginLogic; |
23 | use PeServer\App\Models\Domain\UserLevel; |
24 | use PeServer\App\Models\SessionKey; |
25 | use PeServer\Core\Http\HttpRequest; |
26 | use PeServer\Core\Mvc\ControllerArgument; |
27 | use PeServer\Core\Mvc\LogicCallMode; |
28 | use PeServer\Core\Mvc\Result\IActionResult; |
29 | use PeServer\Core\Throws\InvalidOperationException; |
30 | |
31 | /** |
32 | * [PAGE] アカウント用コントローラ。 |
33 | */ |
34 | final class AccountController extends PageControllerBase |
35 | { |
36 | public function __construct(ControllerArgument $argument) |
37 | { |
38 | parent::__construct($argument); |
39 | } |
40 | |
41 | public function index(): IActionResult |
42 | { |
43 | if ($this->isLoggedIn()) { |
44 | return $this->user(); |
45 | } else { |
46 | return $this->login_get(); |
47 | } |
48 | } |
49 | |
50 | public function login_get(): IActionResult |
51 | { |
52 | if ($this->isLoggedIn()) { |
53 | return $this->redirectPath('account/user'); |
54 | } |
55 | |
56 | $logic = $this->createLogic(AccountLoginLogic::class); |
57 | $logic->run(LogicCallMode::Initialize); |
58 | |
59 | return $this->view('login', $logic->getViewData()); |
60 | } |
61 | |
62 | public function login_post(): IActionResult |
63 | { |
64 | if ($this->isLoggedIn()) { |
65 | return $this->redirectPath('account/user'); |
66 | } |
67 | |
68 | $logic = $this->createLogic(AccountLoginLogic::class); |
69 | if ($logic->run(LogicCallMode::Submit)) { |
70 | if ($this->stores->session->tryGet(SessionKey::ACCOUNT, $account)) { |
71 | /** @var SessionAccount $account */ |
72 | if ($account->level === UserLevel::SETUP) { |
73 | return $this->redirectPath('management/setup'); |
74 | } |
75 | } |
76 | |
77 | return $this->redirectPath('/account'); |
78 | } |
79 | |
80 | return $this->view('login', $logic->getViewData()); |
81 | } |
82 | |
83 | public function logout(): IActionResult |
84 | { |
85 | $logic = $this->createLogic(AccountLogoutLogic::class); |
86 | $logic->run(LogicCallMode::Submit); |
87 | |
88 | return $this->redirectPath('/'); |
89 | } |
90 | |
91 | public function signup_step1_get(): IActionResult |
92 | { |
93 | $logic = $this->createLogic(AccountSignupStep1Logic::class); |
94 | $logic->run(LogicCallMode::Initialize); |
95 | |
96 | return $this->view('signup_step1', $logic->getViewData()); |
97 | } |
98 | |
99 | public function signup_step1_post(): IActionResult |
100 | { |
101 | $logic = $this->createLogic(AccountSignupStep1Logic::class); |
102 | if ($logic->run(LogicCallMode::Submit)) { |
103 | return $this->redirectPath("account/signup/notify"); |
104 | } |
105 | |
106 | return $this->view('signup_step1', $logic->getViewData()); |
107 | } |
108 | |
109 | public function signup_notify(): IActionResult |
110 | { |
111 | $logic = $this->createLogic(AccountSignupNotifyLogic::class); |
112 | $logic->run(LogicCallMode::Initialize); |
113 | return $this->view('signup_notify', $logic->getViewData()); |
114 | } |
115 | |
116 | |
117 | public function signup_step2_get(): IActionResult |
118 | { |
119 | $logic = $this->createLogic(AccountSignupStep2Logic::class); |
120 | $logic->run(LogicCallMode::Initialize); |
121 | |
122 | return $this->view('signup_step2', $logic->getViewData()); |
123 | } |
124 | |
125 | public function signup_step2_post(): IActionResult |
126 | { |
127 | $logic = $this->createLogic(AccountSignupStep2Logic::class); |
128 | if ($logic->run(LogicCallMode::Submit)) { |
129 | return $this->redirectPath("/"); |
130 | } |
131 | |
132 | return $this->view('signup_step2', $logic->getViewData()); |
133 | } |
134 | |
135 | |
136 | public function user(): IActionResult |
137 | { |
138 | $logic = $this->createLogic(AccountUserLogic::class); |
139 | $logic->run(LogicCallMode::Initialize); |
140 | |
141 | return $this->view('user', $logic->getViewData()); |
142 | } |
143 | |
144 | public function user_edit_get(): IActionResult |
145 | { |
146 | $logic = $this->createLogic(AccountUserEditLogic::class); |
147 | $logic->run(LogicCallMode::Initialize); |
148 | |
149 | return $this->view('user_edit', $logic->getViewData()); |
150 | } |
151 | |
152 | public function user_edit_post(): IActionResult |
153 | { |
154 | $logic = $this->createLogic(AccountUserEditLogic::class); |
155 | if ($logic->run(LogicCallMode::Submit)) { |
156 | return $this->redirectPath('account/user'); |
157 | } |
158 | |
159 | return $this->view('user_edit', $logic->getViewData()); |
160 | } |
161 | |
162 | public function user_api_get(): IActionResult |
163 | { |
164 | $logic = $this->createLogic(AccountUserApiLogic::class/*, ['$isRegister' => null]*/); |
165 | $logic->run(LogicCallMode::Initialize); |
166 | |
167 | return $this->view('user_api', $logic->getViewData()); |
168 | } |
169 | |
170 | public function user_api_post(): IActionResult |
171 | { |
172 | $logic = $this->createLogic(AccountUserApiLogic::class/*, ['$isRegister' => true]*/); |
173 | if ($logic->run(LogicCallMode::Submit)) { |
174 | return $this->redirectPath('account/user/api'); |
175 | } |
176 | |
177 | return $this->view('user_api', $logic->getViewData()); |
178 | } |
179 | |
180 | public function user_password_get(): IActionResult |
181 | { |
182 | $logic = $this->createLogic(AccountUserPasswordLogic::class); |
183 | $logic->run(LogicCallMode::Initialize); |
184 | |
185 | return $this->view('user_password', $logic->getViewData()); |
186 | } |
187 | |
188 | public function user_password_post(): IActionResult |
189 | { |
190 | $logic = $this->createLogic(AccountUserPasswordLogic::class); |
191 | if ($logic->run(LogicCallMode::Submit)) { |
192 | return $this->redirectPath('account/user'); |
193 | } |
194 | |
195 | return $this->view('user_password', $logic->getViewData()); |
196 | } |
197 | |
198 | public function user_email_get(): IActionResult |
199 | { |
200 | $logic = $this->createLogic(AccountUserEmailLogic::class); |
201 | $logic->run(LogicCallMode::Initialize); |
202 | |
203 | return $this->view('user_email', $logic->getViewData()); |
204 | } |
205 | |
206 | public function user_email_post(): IActionResult |
207 | { |
208 | $logic = $this->createLogic(AccountUserEmailLogic::class); |
209 | if ($logic->run(LogicCallMode::Submit)) { |
210 | if ($logic->equalsResult('confirm', true)) { |
211 | return $this->redirectPath('account/user'); |
212 | } |
213 | return $this->redirectPath('account/user/email'); |
214 | } |
215 | |
216 | return $this->view('user_email', $logic->getViewData()); |
217 | } |
218 | |
219 | private function user_plugin_get_core(bool $isRegister): IActionResult |
220 | { |
221 | $logic = $this->createLogic(AccountUserPluginLogic::class, ['$isRegister' => $isRegister]); |
222 | $logic->run(LogicCallMode::Initialize); |
223 | |
224 | return $this->view('user_plugin', $logic->getViewData()); |
225 | } |
226 | |
227 | private function user_plugin_post_core(bool $isRegister): IActionResult |
228 | { |
229 | $logic = $this->createLogic(AccountUserPluginLogic::class, ['$isRegister' => $isRegister]); |
230 | if ($logic->run(LogicCallMode::Submit)) { |
231 | if ($logic->tryGetResult('plugin_id', $pluginId)) { |
232 | return $this->redirectPath("account/user/plugin/$pluginId"); |
233 | } |
234 | throw new InvalidOperationException(); |
235 | } |
236 | |
237 | return $this->view('user_plugin', $logic->getViewData()); |
238 | } |
239 | |
240 | public function user_plugin_register_get(): IActionResult |
241 | { |
242 | return $this->user_plugin_get_core(true); |
243 | } |
244 | |
245 | public function user_plugin_register_post(): IActionResult |
246 | { |
247 | return $this->user_plugin_post_core(true); |
248 | } |
249 | |
250 | public function user_plugin_update_get(): IActionResult |
251 | { |
252 | return $this->user_plugin_get_core(false); |
253 | } |
254 | |
255 | public function user_plugin_update_post(): IActionResult |
256 | { |
257 | return $this->user_plugin_post_core(false); |
258 | } |
259 | |
260 | public function user_audit_logs_top(): IActionResult |
261 | { |
262 | $logic = $this->createLogic(AccountUserAuditLogLogic::class); |
263 | $logic->run(LogicCallMode::Initialize); |
264 | |
265 | return $this->view('user_audit_logs', $logic->getViewData()); |
266 | } |
267 | |
268 | public function user_audit_logs_page(): IActionResult |
269 | { |
270 | $logic = $this->createLogic(AccountUserAuditLogLogic::class); |
271 | $logic->run(LogicCallMode::Submit); |
272 | |
273 | return $this->view('user_audit_logs', $logic->getViewData()); |
274 | } |
275 | |
276 | public function user_audit_logs_download(): IActionResult |
277 | { |
278 | $logic = $this->createLogic(AccountUserAuditLogDownloadLogic::class); |
279 | $logic->run(LogicCallMode::Submit); |
280 | |
281 | return $this->data($logic->getContent()); |
282 | } |
283 | } |