<?php
namespace Platform\SecurityBundle\Entity\Login;
use Cms\CoreBundle\Util\DateTimeUtils;
use Cms\TenantBundle\Entity\TenantedEntity;
use Common\Util\Tokens;
use Doctrine\ORM\Mapping as ORM;
use Platform\SecurityBundle\Entity\Identity\Account;
/**
* Class ResetToken
* @package Platform\SecurityBundle\Entity\Login
*
* @ORM\Entity(
* repositoryClass = "Platform\SecurityBundle\Doctrine\Login\ResetTokenRepository"
* )
* @ORM\Table(
* name = "cms__security__login__reset_token"
* )
*/
class ResetToken extends TenantedEntity
{
const EXPIRY_HOURS = 24;
const EXPIRY_DURATION = 'PT' . self::EXPIRY_HOURS . 'H';
const STATES__UNUSED = 0;
const STATES__USED = 1;
const STATES__OBSOLETE = 2;
/**
* @var Account
*
* @ORM\ManyToOne(
* targetEntity = "Platform\SecurityBundle\Entity\Identity\Account"
* )
* @ORM\JoinColumn(
* name = "account",
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected $account;
/**
* @var string
*
* @ORM\Column(
* type = "string",
* nullable = false
* )
*/
protected $token;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false
* )
*/
protected $state = self::STATES__UNUSED;
/**
* @var string
*
* @ORM\Column(
* type = "string",
* nullable = false
* )
*/
protected $ipAddress;
/**
*
*/
public function __construct()
{
$this->token = Tokens::generate();
}
/**
* @return Account
*/
public function getAccount()
{
return $this->account;
}
/**
* @param Account $value
* @return $this
*/
public function setAccount(Account $value)
{
$this->account = $value;
return $this;
}
/**
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* @return int
*/
public function getState()
{
return $this->state;
}
/**
* @param int $value
* @return $this
*/
public function setState($value)
{
$this->state = $value;
return $this;
}
/**
* @return bool
*/
public function isExpired()
{
return ($this->getCreatedAt() < DateTimeUtils::beforeCurrent(self::EXPIRY_DURATION));
}
/**
* @return string
*/
public function getIpAddress()
{
return $this->ipAddress;
}
/**
* @param string $value
* @return $this
*/
public function setIpAddress($value)
{
$this->ipAddress = $value;
return $this;
}
}