From ae40fb6d1b271466d85120e9c851ca28c52178a8 Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Sat, 24 Feb 2018 12:48:15 +0100 Subject: [PATCH] * [MOD] Improved exception handling. --- .../web/Controllers/AccountController.php | 54 +++++++++---------- .../web/Controllers/CategoryController.php | 21 ++++---- .../web/Controllers/ClientController.php | 19 +++---- .../web/Controllers/CustomFieldController.php | 25 ++++----- .../web/Controllers/InstallController.php | 7 ++- .../web/Controllers/ItemManagerController.php | 1 - .../web/Controllers/PublicLinkController.php | 31 ++++++----- app/modules/web/Controllers/TagController.php | 41 +++++++------- .../web/Controllers/UserController.php | 45 ++++++++-------- .../web/Controllers/UserGroupController.php | 36 +++++++------ .../web/Controllers/UserProfileController.php | 33 +++++++----- lib/SP/Util/ImageUtil.php | 8 +-- 12 files changed, 165 insertions(+), 156 deletions(-) diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index bf273354..fc870040 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -80,13 +80,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $accountSearchHelper->getAccountSearch(); $this->eventDispatcher->notifyEvent('show.account.search', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -147,13 +147,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->incrementViewCounter($id); $this->eventDispatcher->notifyEvent('show.account', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -233,13 +233,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac } else { ErrorUtil::showErrorFull($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION, 'account-link'); } + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorFull($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION, 'account-link'); } - - $this->view(); } /** @@ -262,13 +262,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveCreate'); $this->eventDispatcher->notifyEvent('show.account.create', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -301,13 +301,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveCopy'); $this->eventDispatcher->notifyEvent('show.account.copy', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -343,13 +343,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->incrementViewCounter($id); $this->eventDispatcher->notifyEvent('show.account.edit', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -381,13 +381,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveDelete'); $this->eventDispatcher->notifyEvent('show.account.delete', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -421,13 +421,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('accountPassDateChange', gmdate('Y-m-d', $accountDetailsResponse->getAccountVData()->getPassDateChange())); $this->eventDispatcher->notifyEvent('show.account.editpass', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -459,13 +459,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveRestore'); $this->eventDispatcher->notifyEvent('show.account.history', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** @@ -486,19 +486,19 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveRequest'); $this->eventDispatcher->notifyEvent('show.account.request', new Event($this)); + + $this->view(); } catch (\Exception $e) { processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } - - $this->view(); } /** * Display account's password * - * @param int $id Account's ID + * @param int $id Account's ID * @param int $isHistory The account's ID refers to history * @throws \Psr\Container\ContainerExceptionInterface */ @@ -534,7 +534,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Copy account's password * - * @param int $id Account's ID + * @param int $id Account's ID * @param int $isHistory The account's ID refers to history * @throws Helpers\HelperException * @throws SPException @@ -602,7 +602,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac __u('Cuenta creada') ); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -616,7 +616,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * @param $id Account's ID * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -646,7 +645,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac __u('Cuenta actualizada') ); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -660,7 +659,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * @param $id Account's ID * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \SP\Core\Dic\ContainerException */ public function saveEditPassAction($id) { @@ -688,7 +686,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac __u('Clave actualizada') ); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -700,7 +698,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves restore action * * @param int $historyId Account's history ID - * @param int $id Account's ID + * @param int $id Account's ID * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php index b455055f..08493209 100644 --- a/app/modules/web/Controllers/CategoryController.php +++ b/app/modules/web/Controllers/CategoryController.php @@ -97,13 +97,13 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->setViewData(); $this->eventDispatcher->notifyEvent('show.category.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -154,20 +154,21 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.category.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id - * @throws \SP\Core\Dic\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -226,7 +227,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría creada')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -240,7 +241,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa * @param $id * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \SP\Core\Dic\ContainerException + * */ public function saveEditAction($id) { @@ -267,7 +268,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría actualizada')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -294,13 +295,13 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.category', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php index 60deb31d..ac7e6947 100644 --- a/app/modules/web/Controllers/ClientController.php +++ b/app/modules/web/Controllers/ClientController.php @@ -98,13 +98,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->setViewData(); $this->eventDispatcher->notifyEvent('show.client.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -155,13 +155,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.client.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -199,8 +199,6 @@ class ClientController extends ControllerBase implements CrudControllerInterface /** * Saves create action - * - * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -225,7 +223,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -237,7 +235,6 @@ class ClientController extends ControllerBase implements CrudControllerInterface * Saves edit action * * @param $id - * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -260,7 +257,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente actualizado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); @@ -287,13 +284,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.client', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php index ade376cd..bf0e7075 100644 --- a/app/modules/web/Controllers/CustomFieldController.php +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -28,7 +28,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; -use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\CustomFieldDefinitionData; use SP\Forms\CustomFieldDefForm; @@ -100,13 +99,13 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->setViewData(); $this->eventDispatcher->notifyEvent('show.customField.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponse(1, $e->getMessage()); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -160,19 +159,21 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.customField.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -188,7 +189,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->eventDispatcher->notifyEvent('delete.customField', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo eliminado')); - } catch (SPException $e) { + } catch (\Exception $e) { processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); @@ -214,11 +215,11 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { + $this->returnJsonResponseException($e); + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -226,7 +227,6 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte * Saves edit action * * @param $id - * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -244,8 +244,8 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo actualizado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { + $this->returnJsonResponseException($e); + } catch (\Exception $e) { processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); @@ -285,6 +285,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/app/modules/web/Controllers/InstallController.php b/app/modules/web/Controllers/InstallController.php index 5bff9f02..3b07a9f7 100644 --- a/app/modules/web/Controllers/InstallController.php +++ b/app/modules/web/Controllers/InstallController.php @@ -30,6 +30,7 @@ use SP\Core\Exceptions\SPException; use SP\Core\Install\Installer; use SP\Core\Language; use SP\DataModel\InstallData; +use SP\Http\JsonResponse; use SP\Http\Request; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -119,11 +120,9 @@ class InstallController extends ControllerBase try { Installer::run($installData); - $this->returnJsonResponse(0, __('Instalación finalizada')); - } catch (SPException $e) { - $this->returnJsonResponse(1, $e->getMessage(), [$e->getHint()]); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __('Instalación finalizada')); } catch (\Exception $e) { - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ItemManagerController.php b/app/modules/web/Controllers/ItemManagerController.php index 1a8133de..5dad613a 100644 --- a/app/modules/web/Controllers/ItemManagerController.php +++ b/app/modules/web/Controllers/ItemManagerController.php @@ -77,7 +77,6 @@ class ItemManagerController extends ControllerBase * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException - * @throws \SP\Core\Exceptions\InvalidArgumentException */ protected function getGridTabs() { diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index 426d9a8a..b28d0eaf 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -99,13 +99,13 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->setViewData(); $this->eventDispatcher->notifyEvent('show.publicLink.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -158,7 +158,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -182,19 +182,21 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.publicLink.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -211,10 +213,10 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->eventDispatcher->notifyEvent('delete.publicLink', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace eliminado')); - } catch (SPException $e) { + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -241,11 +243,11 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -278,13 +280,13 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.publicLink', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -292,6 +294,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php index 58622b00..c9ba6f9a 100644 --- a/app/modules/web/Controllers/TagController.php +++ b/app/modules/web/Controllers/TagController.php @@ -28,7 +28,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; -use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\TagData; use SP\Forms\TagForm; @@ -98,13 +97,13 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->setViewData(); $this->eventDispatcher->notifyEvent('show.tag.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -153,19 +152,21 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.tag.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -181,17 +182,15 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->eventDispatcher->notifyEvent('delete.tag', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta eliminada')); - } catch (SPException $e) { + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } /** * Saves create action - * - * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -209,11 +208,11 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta creada')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { + $this->returnJsonResponseException($e); + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -221,7 +220,6 @@ class TagController extends ControllerBase implements CrudControllerInterface * Saves edit action * * @param $id - * @throws \SP\Core\Dic\ContainerException */ public function saveEditAction($id) { @@ -239,11 +237,11 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta actualizada')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { + $this->returnJsonResponseException($e); + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -266,13 +264,13 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.tag', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -280,6 +278,7 @@ class TagController extends ControllerBase implements CrudControllerInterface * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/app/modules/web/Controllers/UserController.php b/app/modules/web/Controllers/UserController.php index 486fbb89..f79cda34 100644 --- a/app/modules/web/Controllers/UserController.php +++ b/app/modules/web/Controllers/UserController.php @@ -27,7 +27,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; -use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\Core\SessionUtil; use SP\DataModel\UserData; @@ -102,13 +101,13 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->setViewData(); $this->eventDispatcher->notifyEvent('show.user.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -163,13 +162,13 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.user.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -199,19 +198,21 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->view->assign('user', $user); $this->eventDispatcher->notifyEvent('show.user.editPass', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -230,10 +231,10 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->eventDispatcher->notifyEvent('delete.user', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario eliminado')); - } catch (SPException $e) { + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -269,11 +270,11 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -281,6 +282,8 @@ class UserController extends ControllerBase implements CrudControllerInterface * Saves edit action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function saveEditAction($id) { @@ -312,11 +315,11 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario actualizado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -342,11 +345,11 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Clave actualizada')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -370,13 +373,13 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.user', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** diff --git a/app/modules/web/Controllers/UserGroupController.php b/app/modules/web/Controllers/UserGroupController.php index 3c5c4ef4..ab0a4276 100644 --- a/app/modules/web/Controllers/UserGroupController.php +++ b/app/modules/web/Controllers/UserGroupController.php @@ -27,7 +27,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; -use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\UserGroupData; use SP\Forms\UserGroupForm; @@ -104,13 +103,13 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->setViewData(); $this->eventDispatcher->notifyEvent('show.userGroup.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -163,19 +162,21 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.userGroup.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -192,10 +193,10 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->eventDispatcher->notifyEvent('delete.userGroup', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo eliminado')); - } catch (SPException $e) { + } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -224,11 +225,11 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -236,6 +237,8 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf * Saves edit action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function saveEditAction($id) { @@ -259,11 +262,11 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo actualizado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -286,13 +289,13 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.userGroup', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -300,6 +303,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/app/modules/web/Controllers/UserProfileController.php b/app/modules/web/Controllers/UserProfileController.php index 5050f75b..884cdd8a 100644 --- a/app/modules/web/Controllers/UserProfileController.php +++ b/app/modules/web/Controllers/UserProfileController.php @@ -96,13 +96,13 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->setViewData(); $this->eventDispatcher->notifyEvent('show.userProfile.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(1, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -155,19 +155,21 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.userProfile.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** * Delete action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function deleteAction($id) { @@ -187,7 +189,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -215,11 +217,11 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil creado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -227,6 +229,8 @@ class UserProfileController extends ControllerBase implements CrudControllerInte * Saves edit action * * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function saveEditAction($id) { @@ -249,11 +253,11 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil actualizado')); } catch (ValidationException $e) { - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } } @@ -276,13 +280,13 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->setViewData($id); $this->eventDispatcher->notifyEvent('show.userProfile', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); } catch (\Exception $e) { processException($e); - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + $this->returnJsonResponseException($e); } - - $this->returnJsonResponseData(['html' => $this->render()]); } /** @@ -290,6 +294,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/lib/SP/Util/ImageUtil.php b/lib/SP/Util/ImageUtil.php index 0a26cb70..81b766e6 100644 --- a/lib/SP/Util/ImageUtil.php +++ b/lib/SP/Util/ImageUtil.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link http://syspass.org + * @author nuxsmin + * @link http://syspass.org * @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -24,7 +24,6 @@ namespace SP\Util; -use SP\Core\Init; use SP\Log\LogUtil; defined('APP_ROOT') || die(); @@ -67,7 +66,7 @@ class ImageUtil imagefilledrectangle($im, 0, 0, $width, 30, $bgColor); // Ruta de la fuente - $font = Init::$SERVERROOT . '/css/fonts/NotoSans-Regular-webfont.ttf'; + $font = PUBLIC_PATH . '/css/fonts/NotoSans-Regular-webfont.ttf'; // Sombra // imagettftext($im, 14, 0, 13, 23, $shadowColor, $font, $text); @@ -91,6 +90,7 @@ class ImageUtil * * @param $image string La imagen a redimensionar * @return bool|string + * @throws \SP\Core\Exceptions\SPException */ public static function createThumbnail($image) {