-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tamás András Horváth <[email protected]>
- Loading branch information
Showing
7 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Handler\Account; | ||
|
||
use App\Service\AccountServiceInterface; | ||
use App\Middleware\UserMiddleware; | ||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Laminas\InputFilter\InputFilterInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
final class RejectHandler implements RequestHandlerInterface | ||
{ | ||
public function __construct( | ||
private AccountServiceInterface $accountService, | ||
private InputFilterInterface $accountRejectFilter | ||
) { | ||
$this->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' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Handler\Account; | ||
|
||
use App\InputFilter\AccountRejectFilter; | ||
use App\Service\AccountServiceInterface; | ||
use Laminas\InputFilter\InputFilterPluginManager; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class RejectHandlerFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): RejectHandler | ||
{ | ||
/** @var InputFilterPluginManager $pluginManager */ | ||
$pluginManager = $container->get(InputFilterPluginManager::class); | ||
$inputFilter = $pluginManager->get(AccountRejectFilter::class); | ||
|
||
return new RejectHandler( | ||
$container->get(AccountServiceInterface::class), | ||
$inputFilter | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\InputFilter; | ||
|
||
use Laminas\Filter; | ||
use Laminas\InputFilter\InputFilter; | ||
use Laminas\Validator; | ||
|
||
/** phpcs:disable */ | ||
class AccountRejectFilter extends InputFilter | ||
{ | ||
public function init() | ||
{ | ||
$this->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 protected]", | ||
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters