mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Created entity to persist rest tokens
This commit is contained in:
parent
bbef3444c2
commit
56b2bd3d56
3 changed files with 102 additions and 0 deletions
|
@ -8,3 +8,7 @@ SHORTCODE_CHARS=
|
|||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
|
||||
# Rest authentication
|
||||
REST_USER=
|
||||
REST_PASSWORD=
|
||||
|
|
9
config/autoload/rest.global.php
Normal file
9
config/autoload/rest.global.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
return [
|
||||
|
||||
'rest' => [
|
||||
'username' => getenv('REST_USER'),
|
||||
'password' => getenv('REST_PASSWORD'),
|
||||
],
|
||||
|
||||
];
|
89
src/Entity/RestToken.php
Normal file
89
src/Entity/RestToken.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
namespace Acelaya\UrlShortener\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class RestToken
|
||||
* @author
|
||||
* @link
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="rest_tokens")
|
||||
*/
|
||||
class RestToken extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* The default interval is 20 minutes
|
||||
*/
|
||||
const DEFAULT_INTERVAL = 'PT20M';
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @ORM\Column(type="datetime", name="expiration_date", nullable=false)
|
||||
*/
|
||||
protected $expirationDate;
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(nullable=false)
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->updateExpiration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpirationDate()
|
||||
{
|
||||
return $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $expirationDate
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpirationDate($expirationDate)
|
||||
{
|
||||
$this->expirationDate = $expirationDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
* @return $this
|
||||
*/
|
||||
public function setToken($token)
|
||||
{
|
||||
$this->token = $token;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
{
|
||||
return new \DateTime() > $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the expiration of the token, setting it to the default interval in the future
|
||||
* @return $this
|
||||
*/
|
||||
public function updateExpiration()
|
||||
{
|
||||
return $this->setExpirationDate((new \DateTime())->add(new \DateInterval(self::DEFAULT_INTERVAL)));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue