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

  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. /**
  17.  * @ExclusionPolicy("all")
  18.  */
  19. class UserTwoFactor
  20. {
  21.     private int $id;
  22.     private UserInterface $user;
  23.     /**
  24.      * @Expose
  25.      * @Groups({"profile"})
  26.      */
  27.     private ?string $method null;
  28.     private ?string $options null;
  29.     public function __construct(TwoFactorInterface $user)
  30.     {
  31.         /** @var UserInterface $user */
  32.         $this->user $user;
  33.     }
  34.     public function getMethod(): ?string
  35.     {
  36.         return $this->method;
  37.     }
  38.     /**
  39.      * @return static
  40.      */
  41.     public function setMethod(?string $twoFactorType)
  42.     {
  43.         $this->method $twoFactorType;
  44.         return $this;
  45.     }
  46.     /**
  47.      * @return array{
  48.      *     backupCodes?: string[],
  49.      *     authCode?: string,
  50.      *     googleAuthenticatorSecret?: string,
  51.      *     totpSecret?: string,
  52.      *     trustedVersion?: int,
  53.      *     googleAuthenticatorUsername?: string,
  54.      *     googleAuthenticatorSecret?: string,
  55.      * }
  56.      */
  57.     public function getOptions(): ?array
  58.     {
  59.         if (null === $this->options) {
  60.             return null;
  61.         }
  62.         /**
  63.          * @var array{
  64.          *     backupCodes?: string[],
  65.          *     authCode?: string,
  66.          *     googleAuthenticatorSecret?: string,
  67.          *     totpSecret?: string,
  68.          *     trustedVersion?: int,
  69.          *     googleAuthenticatorUsername?: string,
  70.          *     googleAuthenticatorSecret?: string,
  71.          * }
  72.          */
  73.         return \json_decode($this->optionstrue\JSON_THROW_ON_ERROR);
  74.     }
  75.     /**
  76.      * @param mixed[] $options
  77.      *
  78.      * @return static
  79.      */
  80.     public function setOptions(?array $options)
  81.     {
  82.         $this->options $options \json_encode($options\JSON_THROW_ON_ERROR) : null;
  83.         return $this;
  84.     }
  85. }