src/Platform/SecurityBundle/Entity/Login/ResetToken.php line 22

Open in your IDE?
  1. <?php
  2. namespace Platform\SecurityBundle\Entity\Login;
  3. use Cms\CoreBundle\Util\DateTimeUtils;
  4. use Cms\TenantBundle\Entity\TenantedEntity;
  5. use Common\Util\Tokens;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Platform\SecurityBundle\Entity\Identity\Account;
  8. /**
  9.  * Class ResetToken
  10.  * @package Platform\SecurityBundle\Entity\Login
  11.  *
  12.  * @ORM\Entity(
  13.  *  repositoryClass = "Platform\SecurityBundle\Doctrine\Login\ResetTokenRepository"
  14.  * )
  15.  * @ORM\Table(
  16.  *  name = "cms__security__login__reset_token"
  17.  * )
  18.  */
  19. class ResetToken extends TenantedEntity
  20. {
  21.     const EXPIRY_HOURS 24;
  22.     const EXPIRY_DURATION 'PT' self::EXPIRY_HOURS 'H';
  23.     const STATES__UNUSED 0;
  24.     const STATES__USED 1;
  25.     const STATES__OBSOLETE 2;
  26.     /**
  27.      * @var Account
  28.      *
  29.      * @ORM\ManyToOne(
  30.      *  targetEntity = "Platform\SecurityBundle\Entity\Identity\Account"
  31.      * )
  32.      * @ORM\JoinColumn(
  33.      *  name = "account",
  34.      *  referencedColumnName = "id",
  35.      *  onDelete = "CASCADE"
  36.      * )
  37.      */
  38.     protected $account;
  39.     /**
  40.      * @var string
  41.      *
  42.      * @ORM\Column(
  43.      *  type = "string",
  44.      *  nullable = false
  45.      * )
  46.      */
  47.     protected $token;
  48.     /**
  49.      * @var int
  50.      *
  51.      * @ORM\Column(
  52.      *  type = "integer",
  53.      *  nullable = false
  54.      * )
  55.      */
  56.     protected $state self::STATES__UNUSED;
  57.     /**
  58.      * @var string
  59.      *
  60.      * @ORM\Column(
  61.      *  type = "string",
  62.      *  nullable = false
  63.      * )
  64.      */
  65.     protected $ipAddress;
  66.     /**
  67.      *
  68.      */
  69.     public function __construct()
  70.     {
  71.         $this->token Tokens::generate();
  72.     }
  73.     /**
  74.      * @return Account
  75.      */
  76.     public function getAccount()
  77.     {
  78.         return $this->account;
  79.     }
  80.     /**
  81.      * @param Account $value
  82.      * @return $this
  83.      */
  84.     public function setAccount(Account $value)
  85.     {
  86.         $this->account $value;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return string
  91.      */
  92.     public function getToken()
  93.     {
  94.         return $this->token;
  95.     }
  96.     /**
  97.      * @return int
  98.      */
  99.     public function getState()
  100.     {
  101.         return $this->state;
  102.     }
  103.     /**
  104.      * @param int $value
  105.      * @return $this
  106.      */
  107.     public function setState($value)
  108.     {
  109.         $this->state $value;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return bool
  114.      */
  115.     public function isExpired()
  116.     {
  117.         return ($this->getCreatedAt() < DateTimeUtils::beforeCurrent(self::EXPIRY_DURATION));
  118.     }
  119.     /**
  120.      * @return string
  121.      */
  122.     public function getIpAddress()
  123.     {
  124.         return $this->ipAddress;
  125.     }
  126.     /**
  127.      * @param string $value
  128.      * @return $this
  129.      */
  130.     public function setIpAddress($value)
  131.     {
  132.         $this->ipAddress $value;
  133.         return $this;
  134.     }
  135. }