<?php
namespace Platform\SecurityBundle\Entity\Login;
use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableTrait;
use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableInterface;
use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableTrait;
use Cms\TenantBundle\Model\TenantableInterface;
use Cms\TenantBundle\Model\TenantableTrait;
use Doctrine\ORM\Mapping as ORM;
use Platform\SecurityBundle\Entity\Identity\Account;
use Exception;
/**
* Class Attempt
* @package Platform\SecurityBundle\Entity\Login
*
* @ORM\Entity(
* repositoryClass = "Platform\SecurityBundle\Doctrine\Login\AttemptRepository"
* )
* @ORM\Table(
* name = "cms__security__login__attempt"
* )
*/
class Attempt implements
IdentifiableInterface,
TenantableInterface,
TimestampableInterface
{
use IdentifiableTrait;
use TenantableTrait;
use TimestampableTrait;
public const AUTH_TYPES = [
self::AUTH_TYPE__WEB,
self::AUTH_TYPE__API,
];
public const AUTH_TYPE__WEB = 1;
public const AUTH_TYPE__API = 2;
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false
* )
*/
protected bool $status = false;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true
* )
*/
protected ?string $message = null;
/**
* @var Account|null
*
* @ORM\ManyToOne(
* targetEntity = "Platform\SecurityBundle\Entity\Identity\Account"
* )
* @ORM\JoinColumn(
* name = "account",
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected ?Account $account = null;
/**
* TODO: make this not nullable?
*
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true
* )
*/
protected ?string $ip = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true
* )
*/
protected ?string $redirect = null;
/**
* @var array|null
*
* @ORM\Column(
* type = "json",
* nullable = true
* )
*/
protected ?array $debugging = null;
/**
* @var int
*
* @ORM\Column(
* type = "smallint",
* nullable = false,
* options = {
* "default" = Attempt::AUTH_TYPE__WEB,
* },
* )
*/
protected int $authType = self::AUTH_TYPE__WEB;
/**
* @return bool
*/
public function getStatus(): bool
{
return $this->status;
}
/**
* @return string|null
*/
public function getMessage(): ?string
{
return $this->message;
}
/**
* @return Account|null
*/
public function getAccount(): ?Account
{
return $this->account;
}
/**
* @return string|null
*/
public function getIp(): ?string
{
return $this->ip;
}
/**
* @return string|null
*/
public function getRedirect(): ?string
{
return $this->redirect;
}
/**
* @return int
*/
public function getAuthType(): int
{
return $this->authType;
}
/**
* @param bool $value
* @return $this
*/
public function setStatus(bool $value): self
{
$this->status = ($value === true);
return $this;
}
/**
* @param string|null $value
* @return $this
*/
public function setMessage(?string $value): self
{
$this->message = $value;
return $this;
}
/**
* @param Account $value
* @return $this
*/
public function setAccount(Account $value): self
{
$this->account = $value;
return $this;
}
/**
* @param string|null $value
* @return $this
*/
public function setIp(?string $value): self
{
$this->ip = $value;
return $this;
}
/**
* @param string|null $value
* @return $this
*/
public function setRedirect(?string $value): self
{
$this->redirect = $value;
return $this;
}
/**
* @return array|null
*/
public function getDebugging(): ?array
{
return $this->debugging;
}
/**
* @param array|null $value
* @return $this
*/
public function setDebugging(?array $value): self
{
$this->debugging = $value;
return $this;
}
/**
* @param int $authType
* @return $this
* @throws Exception
*/
public function setAuthType(int $authType): self
{
if ( ! in_array($authType, self::AUTH_TYPES, true)) {
throw new Exception();
}
$this->authType = $authType;
return $this;
}
}