Loading app/src/Listeners/JwtListener.php +10 −1 Original line number Diff line number Diff line Loading @@ -44,16 +44,21 @@ class JwtListener /** * @param AuthenticationFailureEvent $event * * @throws JsonException */ public function onAuthenticationFailureResponse(AuthenticationFailureEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Неверный email или пароль'); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTInvalidEvent $event * * @throws JsonException */ public function onJWTInvalid(JWTInvalidEvent $event): void { Loading @@ -66,18 +71,22 @@ class JwtListener /** * @param JWTNotFoundEvent $event * * @throws JsonException */ public function onJWTNotFound(JWTNotFoundEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Отсутствует токен'); $response->setStatusCode(Response::HTTP_FORBIDDEN); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTExpiredEvent $event * * @throws JsonException */ public function onJWTExpired(JWTExpiredEvent $event): void { Loading app/src/Listeners/KernelExceptionListener.php +3 −3 Original line number Diff line number Diff line Loading @@ -8,17 +8,17 @@ use Symfony\Component\HttpKernel\KernelEvents; class KernelExceptionListener { public static function getSubscribedEvents() public static function getSubscribedEvents(): array { return [ KernelEvents::EXCEPTION => 'onKernelException', ]; } public function onKernelException(ExceptionEvent $event) public function onKernelException(ExceptionEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->setStatusCode(Response::HTTP_FORBIDDEN); $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR); $response->addError($event->getThrowable()->getMessage()); $event->setResponse($response->getResponse()); } Loading app/src/Service/Action/UserBaseActionService.php +2 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace App\Service\Action; use App\Entity\User; use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Service\Attribute\Required; abstract class UserBaseActionService extends BaseActionService Loading @@ -23,6 +24,7 @@ abstract class UserBaseActionService extends BaseActionService public function customValidate(): bool { if ($this->user === null) { $this->responseService->setStatusCode(Response::HTTP_UNAUTHORIZED); $this->responseService->addError('Вы не авторизованы'); return false; } Loading Loading
app/src/Listeners/JwtListener.php +10 −1 Original line number Diff line number Diff line Loading @@ -44,16 +44,21 @@ class JwtListener /** * @param AuthenticationFailureEvent $event * * @throws JsonException */ public function onAuthenticationFailureResponse(AuthenticationFailureEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Неверный email или пароль'); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTInvalidEvent $event * * @throws JsonException */ public function onJWTInvalid(JWTInvalidEvent $event): void { Loading @@ -66,18 +71,22 @@ class JwtListener /** * @param JWTNotFoundEvent $event * * @throws JsonException */ public function onJWTNotFound(JWTNotFoundEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Отсутствует токен'); $response->setStatusCode(Response::HTTP_FORBIDDEN); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTExpiredEvent $event * * @throws JsonException */ public function onJWTExpired(JWTExpiredEvent $event): void { Loading
app/src/Listeners/KernelExceptionListener.php +3 −3 Original line number Diff line number Diff line Loading @@ -8,17 +8,17 @@ use Symfony\Component\HttpKernel\KernelEvents; class KernelExceptionListener { public static function getSubscribedEvents() public static function getSubscribedEvents(): array { return [ KernelEvents::EXCEPTION => 'onKernelException', ]; } public function onKernelException(ExceptionEvent $event) public function onKernelException(ExceptionEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->setStatusCode(Response::HTTP_FORBIDDEN); $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR); $response->addError($event->getThrowable()->getMessage()); $event->setResponse($response->getResponse()); } Loading
app/src/Service/Action/UserBaseActionService.php +2 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace App\Service\Action; use App\Entity\User; use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Service\Attribute\Required; abstract class UserBaseActionService extends BaseActionService Loading @@ -23,6 +24,7 @@ abstract class UserBaseActionService extends BaseActionService public function customValidate(): bool { if ($this->user === null) { $this->responseService->setStatusCode(Response::HTTP_UNAUTHORIZED); $this->responseService->addError('Вы не авторизованы'); return false; } Loading