src/Platform/SecurityBundle/Entity/Login/Attempt.php line 26

Open in your IDE?
  1. <?php
  2. namespace Platform\SecurityBundle\Entity\Login;
  3. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
  4. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableTrait;
  5. use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableInterface;
  6. use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableTrait;
  7. use Cms\TenantBundle\Model\TenantableInterface;
  8. use Cms\TenantBundle\Model\TenantableTrait;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Platform\SecurityBundle\Entity\Identity\Account;
  11. use Exception;
  12. /**
  13.  * Class Attempt
  14.  * @package Platform\SecurityBundle\Entity\Login
  15.  *
  16.  * @ORM\Entity(
  17.  *     repositoryClass = "Platform\SecurityBundle\Doctrine\Login\AttemptRepository"
  18.  * )
  19.  * @ORM\Table(
  20.  *     name = "cms__security__login__attempt"
  21.  * )
  22.  */
  23. class Attempt implements
  24.     IdentifiableInterface,
  25.     TenantableInterface,
  26.     TimestampableInterface
  27. {
  28.     use IdentifiableTrait;
  29.     use TenantableTrait;
  30.     use TimestampableTrait;
  31.     public const AUTH_TYPES = [
  32.         self::AUTH_TYPE__WEB,
  33.         self::AUTH_TYPE__API,
  34.     ];
  35.     public const AUTH_TYPE__WEB 1;
  36.     public const AUTH_TYPE__API 2;
  37.     /**
  38.      * @var bool
  39.      *
  40.      * @ORM\Column(
  41.      *     type = "boolean",
  42.      *     nullable = false
  43.      * )
  44.      */
  45.     protected bool $status false;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(
  50.      *  type = "string",
  51.      *  nullable = true
  52.      * )
  53.      */
  54.     protected ?string $message null;
  55.     /**
  56.      * @var Account|null
  57.      *
  58.      * @ORM\ManyToOne(
  59.      *     targetEntity = "Platform\SecurityBundle\Entity\Identity\Account"
  60.      * )
  61.      * @ORM\JoinColumn(
  62.      *     name = "account",
  63.      *     referencedColumnName = "id",
  64.      *     onDelete = "CASCADE"
  65.      * )
  66.      */
  67.     protected ?Account $account null;
  68.     /**
  69.      * TODO: make this not nullable?
  70.      *
  71.      * @var string|null
  72.      *
  73.      * @ORM\Column(
  74.      *     type = "string",
  75.      *     nullable = true
  76.      * )
  77.      */
  78.     protected ?string $ip null;
  79.     /**
  80.      * @var string|null
  81.      *
  82.      * @ORM\Column(
  83.      *     type = "string",
  84.      *     nullable = true
  85.      * )
  86.      */
  87.     protected ?string $redirect null;
  88.     /**
  89.      * @var array|null
  90.      *
  91.      * @ORM\Column(
  92.      *     type = "json",
  93.      *     nullable = true
  94.      * )
  95.      */
  96.     protected ?array $debugging null;
  97.     /**
  98.      * @var int
  99.      *
  100.      * @ORM\Column(
  101.      *     type = "smallint",
  102.      *     nullable = false,
  103.      *     options = {
  104.      *         "default" = Attempt::AUTH_TYPE__WEB,
  105.      *     },
  106.      * )
  107.      */
  108.     protected int $authType self::AUTH_TYPE__WEB;
  109.     /**
  110.      * @return bool
  111.      */
  112.     public function getStatus(): bool
  113.     {
  114.         return $this->status;
  115.     }
  116.     /**
  117.      * @return string|null
  118.      */
  119.     public function getMessage(): ?string
  120.     {
  121.         return $this->message;
  122.     }
  123.     /**
  124.      * @return Account|null
  125.      */
  126.     public function getAccount(): ?Account
  127.     {
  128.         return $this->account;
  129.     }
  130.     /**
  131.      * @return string|null
  132.      */
  133.     public function getIp(): ?string
  134.     {
  135.         return $this->ip;
  136.     }
  137.     /**
  138.      * @return string|null
  139.      */
  140.     public function getRedirect(): ?string
  141.     {
  142.         return $this->redirect;
  143.     }
  144.     /**
  145.      * @return int
  146.      */
  147.     public function getAuthType(): int
  148.     {
  149.         return $this->authType;
  150.     }
  151.     /**
  152.      * @param bool $value
  153.      * @return $this
  154.      */
  155.     public function setStatus(bool $value): self
  156.     {
  157.         $this->status = ($value === true);
  158.         return $this;
  159.     }
  160.     /**
  161.      * @param string|null $value
  162.      * @return $this
  163.      */
  164.     public function setMessage(?string $value): self
  165.     {
  166.         $this->message $value;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @param Account $value
  171.      * @return $this
  172.      */
  173.     public function setAccount(Account $value): self
  174.     {
  175.         $this->account $value;
  176.         return $this;
  177.     }
  178.     /**
  179.      * @param string|null $value
  180.      * @return $this
  181.      */
  182.     public function setIp(?string $value): self
  183.     {
  184.         $this->ip $value;
  185.         return $this;
  186.     }
  187.     /**
  188.      * @param string|null $value
  189.      * @return $this
  190.      */
  191.     public function setRedirect(?string $value): self
  192.     {
  193.         $this->redirect $value;
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return array|null
  198.      */
  199.     public function getDebugging(): ?array
  200.     {
  201.         return $this->debugging;
  202.     }
  203.     /**
  204.      * @param array|null $value
  205.      * @return $this
  206.      */
  207.     public function setDebugging(?array $value): self
  208.     {
  209.         $this->debugging $value;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @param int $authType
  214.      * @return $this
  215.      * @throws Exception
  216.      */
  217.     public function setAuthType(int $authType): self
  218.     {
  219.         if ( ! in_array($authTypeself::AUTH_TYPEStrue)) {
  220.             throw new Exception();
  221.         }
  222.         $this->authType $authType;
  223.         return $this;
  224.     }
  225. }