. */ namespace SP\Modules\Web\Controllers\User; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; /** * Class SaveCreateController */ final class SaveCreateController extends UserSaveBase { use ItemTrait; use JsonTrait; /** * @return bool * @throws JsonException */ public function saveCreateAction() { try { if (!$this->acl->checkUserAccess(AclActionsInterface::USER_CREATE)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(AclActionsInterface::USER_CREATE); $itemData = $this->form->getItemData(); $id = $this->userService->create($itemData); $this->eventDispatcher->notify( 'create.user', new Event( $this, EventMessage::build() ->addDescription(__u('User added')) ->addDetail(__u('User'), $itemData->getName()) ) ); $this->addCustomFieldsForItem(AclActionsInterface::USER, $id, $this->request, $this->customFieldService); $this->checkChangeUserPass($id, $itemData); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('User added')); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }