ApiKey: add new related forms

This commit is contained in:
Thomas Gelf 2017-07-19 18:22:49 +02:00
parent 7d8db0f0c8
commit 70034b5afe
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Form\DirectorForm;
class IcingaForgetApiKeyForm extends DirectorForm
{
/** @var IcingaHost */
protected $host;
public function setHost(IcingaHost $host)
{
$this->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()));
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Form\DirectorForm;
class IcingaGenerateApiKeyForm extends DirectorForm
{
/** @var IcingaHost */
protected $host;
public function setHost(IcingaHost $host)
{
$this->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()));
}
}