Skip to content

Commit 2ff73a3

Browse files
committed
updated routes and handlers
Signed-off-by: MarioRadu <[email protected]>
1 parent 9dd496e commit 2ff73a3

File tree

5 files changed

+4
-91
lines changed

5 files changed

+4
-91
lines changed

public/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Admin/src/Controller/AdminController.php

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ public function __construct(
6565

6666
public function addAction(): ResponseInterface
6767
{
68-
$this->denyRequest(
69-
! $this->isGet() || ! $this->isPost(),
70-
Message::METHOD_NOT_ALLOWED,
71-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
72-
);
73-
7468
if ($this->isPost()) {
7569
$this->adminForm->setData($this->getPostParams());
7670
if ($this->adminForm->isValid()) {
@@ -114,12 +108,6 @@ public function addAction(): ResponseInterface
114108

115109
public function editAction(): ResponseInterface
116110
{
117-
$this->denyRequest(
118-
! $this->isGet() || ! $this->isPost(),
119-
Message::METHOD_NOT_ALLOWED,
120-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
121-
);
122-
123111
$uuid = $this->getAttribute('uuid');
124112

125113
/** @var Admin $admin */
@@ -173,12 +161,6 @@ public function editAction(): ResponseInterface
173161

174162
public function deleteAction(): ResponseInterface
175163
{
176-
$this->denyRequest(
177-
! $this->isDelete(),
178-
Message::METHOD_NOT_ALLOWED,
179-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
180-
);
181-
182164
$uuid = $this->getAttribute('uuid');
183165
if (empty($uuid)) {
184166
return new JsonResponse(
@@ -204,12 +186,6 @@ public function deleteAction(): ResponseInterface
204186

205187
public function listAction(): ResponseInterface
206188
{
207-
$this->denyRequest(
208-
! $this->isGet(),
209-
Message::METHOD_NOT_ALLOWED,
210-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
211-
);
212-
213189
$result = $this->adminService->getAdmins(
214190
$this->getQueryParam('offset', 0, 'int'),
215191
$this->getQueryParam('limit', 30, 'int'),
@@ -223,12 +199,6 @@ public function listAction(): ResponseInterface
223199

224200
public function manageAction(): ResponseInterface
225201
{
226-
$this->denyRequest(
227-
! $this->isGet(),
228-
Message::METHOD_NOT_ALLOWED,
229-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
230-
);
231-
232202
return new HtmlResponse(
233203
$this->template->render('admin::list')
234204
);
@@ -240,18 +210,11 @@ public function manageAction(): ResponseInterface
240210
*/
241211
public function loginAction(): ResponseInterface
242212
{
243-
$this->denyRequest(
244-
! $this->isGet() || ! $this->isPost(),
245-
Message::METHOD_NOT_ALLOWED,
246-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
247-
);
248-
249213
if ($this->authenticationService->hasIdentity()) {
250214
return new RedirectResponse($this->router->generateUri("dashboard"));
251215
}
252216

253217
$form = new LoginForm();
254-
255218
$shouldRebind = $this->messenger->getData('shouldRebind') ?? true;
256219
if ($shouldRebind) {
257220
$this->forms->restoreState($form);
@@ -313,26 +276,15 @@ public function loginAction(): ResponseInterface
313276

314277
public function logoutAction(): ResponseInterface
315278
{
316-
$this->denyRequest(
317-
! $this->isGet(),
318-
Message::METHOD_NOT_ALLOWED,
319-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
320-
);
321-
322279
$this->authenticationService->clearIdentity();
280+
323281
return new RedirectResponse(
324282
$this->router->generateUri('admin', ['action' => 'login'])
325283
);
326284
}
327285

328286
public function accountAction(): ResponseInterface
329287
{
330-
$this->denyRequest(
331-
! $this->isGet() || ! $this->isPost(),
332-
Message::METHOD_NOT_ALLOWED,
333-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
334-
);
335-
336288
$form = new AccountForm();
337289
$changePasswordForm = new ChangePasswordForm();
338290
$identity = $this->authenticationService->getIdentity();
@@ -371,12 +323,6 @@ public function accountAction(): ResponseInterface
371323

372324
public function changePasswordAction(): ResponseInterface
373325
{
374-
$this->denyRequest(
375-
! $this->isGet() || ! $this->isPost(),
376-
Message::METHOD_NOT_ALLOWED,
377-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
378-
);
379-
380326
$changePasswordForm = new ChangePasswordForm();
381327
/** @var AdminIdentity $adminIdentity */
382328
$adminIdentity = $this->authenticationService->getIdentity();
@@ -413,12 +359,6 @@ public function changePasswordAction(): ResponseInterface
413359

414360
public function loginsAction(): ResponseInterface
415361
{
416-
$this->denyRequest(
417-
! $this->isGet(),
418-
Message::METHOD_NOT_ALLOWED,
419-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
420-
);
421-
422362
return new HtmlResponse(
423363
$this->template->render('admin::list-logins')
424364
);
@@ -429,12 +369,6 @@ public function loginsAction(): ResponseInterface
429369
*/
430370
public function listLoginsAction(): ResponseInterface
431371
{
432-
$this->denyRequest(
433-
! $this->isGet(),
434-
Message::METHOD_NOT_ALLOWED,
435-
StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED
436-
);
437-
438372
$result = $this->adminService->getAdminLogins(
439373
$this->getQueryParam('offset', 0, 'int'),
440374
$this->getQueryParam('limit', 30, 'int'),

src/Admin/src/RoutesDelegator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
1818

1919
$app->route(
2020
'/admin[/{action}[/{uuid}]]',
21-
AdminController::class,
22-
[
23-
RequestMethodInterface::METHOD_GET,
24-
RequestMethodInterface::METHOD_POST,
25-
RequestMethodInterface::METHOD_DELETE,
26-
],
21+
AdminController::class, [RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST],
2722
'admin'
2823
);
2924

src/App/assets/js/components/_admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ $(document).ready(() => {
8484
$(document).on('click', '#modalDeleteBtn', () => {
8585
const selections = $("#bsTable").bootstrapTable('getSelections');
8686
const messages = adminDeleteModal.find('.modal-messages');
87-
request('DELETE', `/admin/delete/${selections[0].uuid}`)
87+
request('GET', `/admin/delete/${selections[0].uuid}`)
8888
.then(data => {
8989
messages.html('');
9090
messages.append(

src/App/src/Common/ServerRequestAwareTrait.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,6 @@ public function getAttribute(string $name, mixed $default = null, ?string $cast
176176
return $this->cast($default, $cast);
177177
}
178178

179-
/**
180-
* @return JsonResponse|void
181-
*/
182-
protected function denyRequest(bool $rule, string $message, int $errorCode)
183-
{
184-
if ($rule) {
185-
return new JsonResponse([
186-
'error' => [
187-
'messages' => [
188-
[$message],
189-
],
190-
],
191-
], $errorCode);
192-
}
193-
}
194-
195179
private function cast(mixed $value, ?string $to = null): mixed
196180
{
197181
return match ($to) {

0 commit comments

Comments
 (0)