From 70034b5afea856b220f83d412b7abab8bfef4527 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 19 Jul 2017 18:22:49 +0200 Subject: [PATCH] ApiKey: add new related forms --- application/forms/IcingaForgetApiKeyForm.php | 34 +++++++++++++++ .../forms/IcingaGenerateApiKeyForm.php | 42 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 application/forms/IcingaForgetApiKeyForm.php create mode 100644 application/forms/IcingaGenerateApiKeyForm.php diff --git a/application/forms/IcingaForgetApiKeyForm.php b/application/forms/IcingaForgetApiKeyForm.php new file mode 100644 index 00000000..d1f475c3 --- /dev/null +++ b/application/forms/IcingaForgetApiKeyForm.php @@ -0,0 +1,34 @@ +host = $host; + return $this; + } + + public function setup() + { + $this->addStandaloneSubmitButton(sprintf( + $this->translate('Drop Self Service API key'), + $this->host->getObjectName() + )); + } + + public function onSuccess() + { + $this->host->set('api_key', null)->store(); + $this->redirectOnSuccess(sprintf($this->translate( + 'The Self Service API key for %s has been dropped' + ), $this->host->getObjectName())); + } +} diff --git a/application/forms/IcingaGenerateApiKeyForm.php b/application/forms/IcingaGenerateApiKeyForm.php new file mode 100644 index 00000000..18980f05 --- /dev/null +++ b/application/forms/IcingaGenerateApiKeyForm.php @@ -0,0 +1,42 @@ +host = $host; + return $this; + } + + public function setup() + { + if ($this->host->getProperty('api_key')) { + $label = $this->translate('Regenerate Self Service API key'); + } else { + $label = $this->translate('Generate Self Service API key'); + } + + $this->addStandaloneSubmitButton(sprintf( + $label, + $this->host->getObjectName() + )); + } + + public function onSuccess() + { + $host = $this->host; + $host->generateApiKey(); + $host->store(); + $this->redirectOnSuccess(sprintf($this->translate( + 'A new Self Service API key for %s has been generated' + ), $host->getObjectName())); + } +}