From 56b2bd3d56073ec3ba4f61d14e824cb21c9cc496 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 4 Jul 2016 14:04:10 +0200 Subject: [PATCH] Created entity to persist rest tokens --- .env.dist | 4 ++ config/autoload/rest.global.php | 9 ++++ src/Entity/RestToken.php | 89 +++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 config/autoload/rest.global.php create mode 100644 src/Entity/RestToken.php diff --git a/.env.dist b/.env.dist index a25e8c2c..d6271d57 100644 --- a/.env.dist +++ b/.env.dist @@ -8,3 +8,7 @@ SHORTCODE_CHARS= DB_USER= DB_PASSWORD= DB_NAME= + +# Rest authentication +REST_USER= +REST_PASSWORD= diff --git a/config/autoload/rest.global.php b/config/autoload/rest.global.php new file mode 100644 index 00000000..6e3fc216 --- /dev/null +++ b/config/autoload/rest.global.php @@ -0,0 +1,9 @@ + [ + 'username' => getenv('REST_USER'), + 'password' => getenv('REST_PASSWORD'), + ], + +]; diff --git a/src/Entity/RestToken.php b/src/Entity/RestToken.php new file mode 100644 index 00000000..d23dc10f --- /dev/null +++ b/src/Entity/RestToken.php @@ -0,0 +1,89 @@ +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))); + } +}