Skip to content

Commit

Permalink
UserController: Introduce addAction, editAction and removeAction
Browse files Browse the repository at this point in the history
refs #8826
  • Loading branch information
Johannes Meyer committed May 20, 2015
1 parent 32d1569 commit 605ae3d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
55 changes: 55 additions & 0 deletions application/controllers/UserController.php
Expand Up @@ -7,6 +7,7 @@
use Icinga\Application\Logger;
use Icinga\Authentication\User\UserBackend;
use Icinga\Authentication\User\UserBackendInterface;
use Icinga\Forms\Config\UserForm;
use Icinga\Web\Controller;
use Icinga\Web\Form;
use Icinga\Web\Notification;
Expand Down Expand Up @@ -100,6 +101,60 @@ function ($b) { return $b->getName(); },
);
}

/**
* Add a user
*/
public function addAction()
{
$form = new UserForm();
$form->setRepository($this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible'));
$form->add()->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Edit a user
*/
public function editAction()
{
$userName = $this->params->getRequired('user');
$backend = $this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Updatable');

$row = $backend->select(array('user_name', 'is_active'))->where('user_name', $userName)->fetchRow();
if ($row === false) {
$this->httpNotFound(sprintf($this->translate('User "%s" not found'), $userName));
}

$form = new UserForm();
$form->setRepository($backend);
$form->edit($userName, get_object_vars($row))->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Remove a user
*/
public function removeAction()
{
$userName = $this->params->getRequired('user');
$backend = $this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible');

if ($backend->select()->where('user_name', $userName)->count() === 0) {
$this->httpNotFound(sprintf($this->translate('User "%s" not found'), $userName));
}

$form = new UserForm();
$form->setRepository($backend);
$form->remove($userName)->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Return all user backends implementing the given interface
*
Expand Down
6 changes: 6 additions & 0 deletions application/views/scripts/user/form.phtml
@@ -0,0 +1,6 @@
<div class="controls">
<?= $tabs->showOnlyCloseButton(); ?>
</div>
<div class="content">
<?= $form; ?>
</div>

0 comments on commit 605ae3d

Please sign in to comment.