diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist index 75c8b9c2..cd1996b9 100644 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -1,7 +1,8 @@ true, + 'debug' => true, 'config_cache_enabled' => false, + ]; diff --git a/module/Rest/config/entity-manager.config.php b/module/Rest/config/entity-manager.config.php new file mode 100644 index 00000000..e9359519 --- /dev/null +++ b/module/Rest/config/entity-manager.config.php @@ -0,0 +1,12 @@ + [ + 'orm' => [ + 'entities_paths' => [ + __DIR__ . '/../src/Entity', + ], + ], + ], + +]; diff --git a/module/Rest/src/Entity/ApiKey.php b/module/Rest/src/Entity/ApiKey.php new file mode 100644 index 00000000..7dc1614f --- /dev/null +++ b/module/Rest/src/Entity/ApiKey.php @@ -0,0 +1,117 @@ +enabled = true; + $this->key = $this->generateV4Uuid(); + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param string $key + * @return $this + */ + public function setKey($key) + { + $this->key = $key; + return $this; + } + + /** + * @return \DateTime + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @param \DateTime $expirationDate + * @return $this + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + return $this; + } + + /** + * @return bool + */ + public function isExpired() + { + if (! isset($this->expirationDate)) { + return false; + } + + return $this->expirationDate >= new \DateTime(); + } + + /** + * @return boolean + */ + public function isEnabled() + { + return $this->enabled; + } + + /** + * @param boolean $enabled + * @return $this + */ + public function setEnabled($enabled) + { + $this->enabled = $enabled; + return $this; + } + + /** + * Tells if this api key is enabled and not expired + * + * @return bool + */ + public function isValid() + { + return $this->isEnabled() && ! $this->isExpired(); + } +}