src/EventSubscriber/PasswordChangedEventSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\PasswordChangedEvent;
  4. use App\Services\ApiConsumerService;
  5. use App\Services\AsymmetricEncryptionService;
  6. use App\Services\Rabbit\Publisher\UsuarioHermesPublisher;
  7. use Doctrine\ORM\EntityNotFoundException;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. final class PasswordChangedEventSubscriber implements EventSubscriberInterface
  10. {
  11. public function __construct(
  12. private AsymmetricEncryptionService $asymmetricEncryptionService,
  13. private ApiConsumerService $apiConsumerService
  14. ) {}
  15. public static function getSubscribedEvents(): array
  16. {
  17. return [PasswordChangedEvent::class => 'onPasswordChanged'];
  18. }
  19. public function onPasswordChanged(PasswordChangedEvent $event): void
  20. {
  21. $response = $this->apiConsumerService->getData(
  22. 'usuario-movil', [
  23. 'username' => $event->username,
  24. // 'userToken' => $event->userToken, //No sé porqeu pero me falla al enviar este.
  25. 'uuid' => $event->uuid
  26. ]
  27. );
  28. if (!$response) throw new EntityNotFoundException('HERMES.NOT_FOUND_ENTITY.USUARIO_MOVIL');
  29. $usuarioMovil = json_decode($response)[0];
  30. $this->apiConsumerService->postData('usuario-movil/'.$usuarioMovil->id, json_encode([
  31. 'plain_password' => $this->asymmetricEncryptionService->publicEncrypt($event->newPassword)
  32. ]));
  33. }
  34. }