vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Entity/UserTwoFactor.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\SecurityBundle\Entity;
  11. use JMS\Serializer\Annotation\ExclusionPolicy;
  12. use JMS\Serializer\Annotation\Expose;
  13. use JMS\Serializer\Annotation\Groups;
  14. use Sulu\Bundle\SecurityBundle\Entity\TwoFactor\TwoFactorInterface;
  15. use Sulu\Component\Security\Authentication\UserInterface;
  16. #[ExclusionPolicy('all')]
  17. class UserTwoFactor
  18. {
  19. private int $id;
  20. private UserInterface $user;
  21. #[Expose]
  22. #[Groups(['profile'])]
  23. private ?string $method = null;
  24. private ?string $options = null;
  25. public function __construct(TwoFactorInterface $user)
  26. {
  27. /** @var UserInterface $user */
  28. $this->user = $user;
  29. }
  30. public function getMethod(): ?string
  31. {
  32. return $this->method;
  33. }
  34. /**
  35. * @return static
  36. */
  37. public function setMethod(?string $twoFactorType)
  38. {
  39. $this->method = $twoFactorType;
  40. return $this;
  41. }
  42. /**
  43. * @return array{
  44. * backupCodes?: string[],
  45. * authCode?: string,
  46. * googleAuthenticatorSecret?: string,
  47. * totpSecret?: string,
  48. * trustedVersion?: int,
  49. * googleAuthenticatorUsername?: string,
  50. * googleAuthenticatorSecret?: string,
  51. * }
  52. */
  53. public function getOptions(): ?array
  54. {
  55. if (null === $this->options) {
  56. return null;
  57. }
  58. /**
  59. * @var array{
  60. * backupCodes?: string[],
  61. * authCode?: string,
  62. * googleAuthenticatorSecret?: string,
  63. * totpSecret?: string,
  64. * trustedVersion?: int,
  65. * googleAuthenticatorUsername?: string,
  66. * googleAuthenticatorSecret?: string,
  67. * }
  68. */
  69. return \json_decode($this->options, true, \JSON_THROW_ON_ERROR);
  70. }
  71. /**
  72. * @param mixed[] $options
  73. *
  74. * @return static
  75. */
  76. public function setOptions(?array $options)
  77. {
  78. $this->options = $options ? \json_encode($options, \JSON_THROW_ON_ERROR) : null;
  79. return $this;
  80. }
  81. }