diff --git a/config/routes.php b/config/routes.php index 8158069..b871be3 100644 --- a/config/routes.php +++ b/config/routes.php @@ -30,4 +30,10 @@ App\Middleware\UserMiddleware::class, App\Handler\Account\PrintHandler::class ], 'admin.api.account.print'); + + $app->post('/admin/api/account/reject', [ + Jwt\Handler\JwtAuthMiddleware::class, + App\Middleware\UserMiddleware::class, + App\Handler\Account\RejectHandler::class + ], 'admin.api.account.reject'); }; diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index e3a72a3..624dd99 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -39,6 +39,7 @@ public function getDependencies(): array Handler\Account\SearchHandler::class => Handler\Account\SearchHandlerFactory::class, Handler\Account\SendHandler::class => Handler\Account\SendHandlerFactory::class, Handler\Account\PrintHandler::class => Handler\Account\PrintHandlerFactory::class, + Handler\Account\RejectHandler::class => Handler\Account\RejectHandlerFactory::class, Handler\Setting\GetHandler::class => Handler\Setting\GetHandlerFactory::class, Service\AccountServiceInterface::class => Service\AccountServiceFactory::class, Service\AuditLogServiceInterface::class => Service\AuditLogServiceFactory::class, @@ -59,6 +60,7 @@ public function getInputFilters(): array 'invokables' => [ InputFilter\AccountSearchFilter::class => InputFilter\AccountSearchFilter::class, InputFilter\AccountSendFilter::class => InputFilter\AccountSendFilter::class, + InputFilter\AccountRejectFilter::class => InputFilter\AccountRejectFilter::class, ], ]; } diff --git a/src/App/src/Handler/Account/RejectHandler.php b/src/App/src/Handler/Account/RejectHandler.php new file mode 100644 index 0000000..9970326 --- /dev/null +++ b/src/App/src/Handler/Account/RejectHandler.php @@ -0,0 +1,49 @@ +accountService = $accountService; + $this->accountRejectFilter = $accountRejectFilter; + } + + public function handle(ServerRequestInterface $request): ResponseInterface + { + $user = $request->getAttribute(UserMiddleware::class); + + $body = $request->getParsedBody(); + + $this->accountRejectFilter->setData($body); + + if (! $this->accountRejectFilter->isValid()) { + return new JsonResponse([ + 'errors' => $this->accountRejectFilter->getMessages(), + ], 422); + } + + $this->accountService->sendRejectNotification( + $user, + $this->accountRejectFilter->getValues()['type'], + $this->accountRejectFilter->getValues()['email'], + ); + + return new JsonResponse([ + 'message' => 'Sikeres elutasító e-mail küldés' + ]); + } +} diff --git a/src/App/src/Handler/Account/RejectHandlerFactory.php b/src/App/src/Handler/Account/RejectHandlerFactory.php new file mode 100644 index 0000000..3c6a718 --- /dev/null +++ b/src/App/src/Handler/Account/RejectHandlerFactory.php @@ -0,0 +1,25 @@ +get(InputFilterPluginManager::class); + $inputFilter = $pluginManager->get(AccountRejectFilter::class); + + return new RejectHandler( + $container->get(AccountServiceInterface::class), + $inputFilter + ); + } +} diff --git a/src/App/src/InputFilter/AccountRejectFilter.php b/src/App/src/InputFilter/AccountRejectFilter.php new file mode 100644 index 0000000..8e8b54e --- /dev/null +++ b/src/App/src/InputFilter/AccountRejectFilter.php @@ -0,0 +1,75 @@ +add([ + 'name' => 'type', + 'allow_empty' => false, + 'validators' => [ + new Validator\NotEmpty([ + 'messages' => [ + Validator\NotEmpty::IS_EMPTY => 'Kötelező a mező kitöltése', + Validator\NotEmpty::INVALID => 'Hibás mező tipus', + ], + ]), + ], + 'filters' => [ + new Filter\StringTrim(), + new Filter\StripTags(), + new Filter\StringToUpper(), + ], + ]); + + $this->add([ + 'name' => 'email', + 'allow_empty' => false, + 'validators' => [ + new Validator\NotEmpty([ + 'messages' => [ + Validator\NotEmpty::IS_EMPTY => 'Kötelező a mező kitöltése', + Validator\NotEmpty::INVALID => 'Hibás mező tipus', + ], + ]), + new Validator\EmailAddress([ + 'messages' => [ + Validator\EmailAddress::INVALID => "Érvénytelen típus megadva. Szöveg adható meg.", + Validator\EmailAddress::INVALID_FORMAT => "A bevitel nem érvényes e-mail cím. Használja az alapformátumot pl. email@kiszolgalo.hu", + Validator\EmailAddress::INVALID_HOSTNAME => "'%hostname%' érvénytelen gazdagépnév", + Validator\EmailAddress::INVALID_MX_RECORD => "'%hostname%' úgy tűnik, hogy az e-mail címhez nincs érvényes MX vagy A rekordja", + Validator\EmailAddress::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address should not be resolved from public network", + Validator\EmailAddress::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format", + Validator\EmailAddress::QUOTED_STRING => "'%localPart%' nem illeszthető idézőjel a szövegbe", + Validator\EmailAddress::INVALID_LOCAL_PART => "'%localPart%' nem érvényes az e-mail cím helyi része", + Validator\EmailAddress::LENGTH_EXCEEDED => "A szöveg meghaladja az engedélyezett hosszúságot", + ], + ]), + new Validator\StringLength([ + 'messages' => [ + Validator\StringLength::TOO_SHORT => 'Legalább %min% karaktert kell tartalmaznia a mezőnek', + Validator\StringLength::TOO_LONG => 'Kevesebb karaktert kell tartalmaznia a mezőnek mint: %max%', + Validator\StringLength::INVALID => 'Hibás mező tipus. Csak szöveg fogadható el', + ], + 'min' => 5, + 'max' => 255, + ]), + ], + 'filters' => [ + new Filter\StringTrim(), + new Filter\StripTags(), + new Filter\StringToLower(), + ], + ]); + } +} +/** phpcs:enable */ diff --git a/src/App/src/Service/AccountService.php b/src/App/src/Service/AccountService.php index dff0d7e..d92fbf4 100644 --- a/src/App/src/Service/AccountService.php +++ b/src/App/src/Service/AccountService.php @@ -80,6 +80,13 @@ public function sendAccount(UserInterface $user, string $id, string $email): voi } } + public function sendRejectNotification(UserInterface $user, string $type, string $email): void + { + $notification = new SimpleNotification("0", $email); + + $this->sendRejectEmail($user, $notification, $type); + } + public function printAccount(UserInterface $user, string $id): ?Dompdf { $account = $this->accountRepository->find($id); @@ -134,4 +141,20 @@ private function printAuthCodeEmail( return $dompdf; } + + private function sendRejectEmail( + UserInterface $user, + NotificationInterface $notification, + string $type + ): void { + $tplData = [ + 'infoMunicipality' => $this->config['app']['municipality'], + 'infoEmail' => $this->config['app']['email'], + 'appURL' => $this->config['app']['url'], + ]; + + $this->mailService->send('reject-type-' . $type, $tplData, $notification); + + $this->auditService->log($user, 'reject-email', null, $type); + } } diff --git a/src/App/src/Service/AccountServiceInterface.php b/src/App/src/Service/AccountServiceInterface.php index 45fc244..a9dd73d 100644 --- a/src/App/src/Service/AccountServiceInterface.php +++ b/src/App/src/Service/AccountServiceInterface.php @@ -27,4 +27,10 @@ public function printAccount( UserInterface $user, string $id ): ?Dompdf; + + public function sendRejectNotification( + UserInterface $user, + string $type, + string $email + ): void; }