Compare commits
No commits in common. "48925f283fa84ab4a9159123e0090c390c8f6401" and "87928dbbc9be610f90eeafad29da553a648fff9c" have entirely different histories.
48925f283f
...
87928dbbc9
|
|
@ -158,27 +158,13 @@ table.bordered_table th {
|
|||
|
||||
/* --- Boxes --- */
|
||||
.filter_options,
|
||||
.form_box,
|
||||
.edit_box,
|
||||
.confirmation_box {
|
||||
border: 1px solid #999999;
|
||||
padding: 1rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
/* --- Detail boxes --- */
|
||||
details {
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
details > summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
details > p {
|
||||
margin: 0.75rem 1rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
/* --- Detail columns --- */
|
||||
input#show_details_checkbox {
|
||||
margin-bottom: 1rem;
|
||||
|
|
@ -188,8 +174,8 @@ input#show_details_checkbox:not(:checked) ~ table .detail_column {
|
|||
display: none;
|
||||
}
|
||||
|
||||
/* --- Form box --- */
|
||||
.form_box p:last-child {
|
||||
/* --- Edit box --- */
|
||||
.edit_box p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,18 +77,4 @@ class ActionResult
|
|||
{
|
||||
return $this->inputData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array that can be merged with other template render data, containing either a field "success" or "error" with the
|
||||
* result message and in case of an error result a field "formData" containing the input data.
|
||||
*/
|
||||
public function getRenderData(): array
|
||||
{
|
||||
$messageKey = $this->isSuccess() ? 'success' : 'error';
|
||||
$renderData = [$messageKey => $this->message];
|
||||
if (!empty($this->inputData)) {
|
||||
$renderData['formData'] = $this->inputData;
|
||||
}
|
||||
return $renderData;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Common;
|
||||
|
||||
use MailAccountAdmin\Exceptions\InputValidationError;
|
||||
|
||||
abstract class FormData
|
||||
{
|
||||
// Abstract methods
|
||||
|
||||
abstract public static function createFromArray($raw): self;
|
||||
|
||||
|
||||
// Input validation - Base types
|
||||
|
||||
protected static function validateString(string $raw, int $minLength = 0, int $maxLength = 5000, string $fieldName = 'Field'): string
|
||||
{
|
||||
if ($raw === '' && $minLength > 0) {
|
||||
throw new InputValidationError("$fieldName is required.");
|
||||
} elseif (strlen($raw) < $minLength) {
|
||||
throw new InputValidationError("$fieldName is too short (minimum $minLength characters).");
|
||||
} elseif (strlen($raw) > 100) {
|
||||
throw new InputValidationError("$fieldName is too long (maximum $maxLength characters).");
|
||||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
protected static function validateBoolOption(string $raw): bool
|
||||
{
|
||||
return $raw !== '';
|
||||
}
|
||||
|
||||
|
||||
// Input validation - Application specific validators
|
||||
|
||||
protected static function validateUsername(string $username, bool $required = true): ?string
|
||||
{
|
||||
if (!$required && $username === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$username = strtolower(
|
||||
self::validateString($username, 3, 100, 'Username')
|
||||
);
|
||||
|
||||
if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+$/', $username) || preg_match('/^\\.|\\.\\.|\\.@|@\\.|\\.$/', $username)) {
|
||||
throw new InputValidationError('Username is not valid (must be a valid mail address).');
|
||||
}
|
||||
return $username;
|
||||
}
|
||||
|
||||
protected static function validatePassword(string $password, string $passwordRepeat, bool $required = true): ?string
|
||||
{
|
||||
if (!$required && $password === '' && $passwordRepeat === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$password = self::validateString($password, 6, 1000, 'Password');
|
||||
|
||||
if ($password !== $passwordRepeat) {
|
||||
throw new InputValidationError('Passwords do not match.');
|
||||
}
|
||||
return $password;
|
||||
}
|
||||
|
||||
protected static function validateHomeDir(string $homeDir, bool $required = true): ?string
|
||||
{
|
||||
if (!$required && $homeDir === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$homeDir = self::validateString($homeDir, 0, 100, 'Home directory');
|
||||
$homeDir = trim($homeDir, '/');
|
||||
|
||||
if (!preg_match('!^[a-z0-9._+-]+(/[a-z0-9._+-]+)*$!i', $homeDir)) {
|
||||
throw new InputValidationError('Home directory is not a valid path.');
|
||||
}
|
||||
return $homeDir;
|
||||
}
|
||||
|
||||
protected static function validateMemo(string $memo): string
|
||||
{
|
||||
return self::validateString($memo, 0, 5000, 'Admin memo');
|
||||
}
|
||||
}
|
||||
|
|
@ -145,13 +145,14 @@ class Dependencies
|
|||
$c->get(SessionHelper::class),
|
||||
$c->get(UserHelper::class),
|
||||
$c->get(AccountHandler::class),
|
||||
$c->get(AccountRepository::class),
|
||||
$c->get(AliasRepository::class),
|
||||
);
|
||||
});
|
||||
$container->set(AccountHandler::class, function (ContainerInterface $c) {
|
||||
return new AccountHandler(
|
||||
$c->get(AccountRepository::class),
|
||||
$c->get(AliasRepository::class),
|
||||
$c->get(DomainRepository::class),
|
||||
$c->get(PasswordHelper::class),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use MailAccountAdmin\Common\SessionHelper;
|
|||
use MailAccountAdmin\Common\UserHelper;
|
||||
use MailAccountAdmin\Exceptions\InputValidationError;
|
||||
use MailAccountAdmin\Frontend\BaseController;
|
||||
use MailAccountAdmin\Repositories\AccountRepository;
|
||||
use MailAccountAdmin\Repositories\AliasRepository;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Views\Twig;
|
||||
|
|
@ -15,11 +17,15 @@ use Slim\Views\Twig;
|
|||
class AccountController extends BaseController
|
||||
{
|
||||
private AccountHandler $accountHandler;
|
||||
private AccountRepository $accountRepository;
|
||||
private AliasRepository $aliasRepository;
|
||||
|
||||
public function __construct(Twig $view, SessionHelper $sessionHelper, UserHelper $userHelper, AccountHandler $accountHandler)
|
||||
public function __construct(Twig $view, SessionHelper $sessionHelper, UserHelper $userHelper, AccountHandler $accountHandler, AccountRepository $accountRepository, AliasRepository $aliasRepository)
|
||||
{
|
||||
parent::__construct($view, $sessionHelper, $userHelper);
|
||||
$this->accountHandler = $accountHandler;
|
||||
$this->accountRepository = $accountRepository;
|
||||
$this->aliasRepository = $aliasRepository;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -52,39 +58,8 @@ class AccountController extends BaseController
|
|||
|
||||
public function showAccountCreate(Request $request, Response $response): Response
|
||||
{
|
||||
$renderData = $this->accountHandler->getPageDataForCreate();
|
||||
|
||||
// If the form has been submitted, add the result message and form input data to the render data array
|
||||
$lastActionResult = $this->sessionHelper->getLastActionResult();
|
||||
if ($lastActionResult !== null) {
|
||||
$renderData = array_merge($renderData, $lastActionResult->getRenderData());
|
||||
}
|
||||
|
||||
return $this->view->render($response, 'account_create.html.twig', $renderData);
|
||||
}
|
||||
|
||||
public function createAccount(Request $request, Response $response): Response
|
||||
{
|
||||
// Parse form data
|
||||
$createData = $request->getParsedBody();
|
||||
|
||||
try {
|
||||
// Validate input
|
||||
$validatedCreateData = AccountCreateData::createFromArray($createData);
|
||||
$newAccountId = $this->accountHandler->createNewAccount($validatedCreateData);
|
||||
|
||||
// Save success result
|
||||
$newAccountName = $validatedCreateData->getUsername();
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createSuccessResult(
|
||||
'Account <a href="/accounts/' . $newAccountId . '">' . $newAccountName . '</a> was created.'
|
||||
));
|
||||
} catch (InputValidationError $e) {
|
||||
// Save error result
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createErrorResult($e->getMessage(), $createData));
|
||||
}
|
||||
|
||||
// Redirect to edit form page via GET (PRG)
|
||||
return $response->withHeader('Location', '/accounts/new')->withStatus(303);
|
||||
// TODO: just a placeholder
|
||||
return $this->showAccounts($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,12 +71,21 @@ class AccountController extends BaseController
|
|||
$accountId = (int)$args['id'];
|
||||
|
||||
// Get account data from database
|
||||
$renderData = $this->accountHandler->getAccountDataForEdit($accountId);
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
|
||||
$renderData = [
|
||||
'id' => $account->getId(),
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'account' => $account,
|
||||
];
|
||||
|
||||
// If the form has been submitted, add the result message and form input data to the render data array
|
||||
$lastActionResult = $this->sessionHelper->getLastActionResult();
|
||||
if ($lastActionResult !== null) {
|
||||
$renderData = array_merge($renderData, $lastActionResult->getRenderData());
|
||||
$resultData = $lastActionResult->isSuccess()
|
||||
? ['success' => $lastActionResult->getMessage()]
|
||||
: ['error' => $lastActionResult->getMessage()];
|
||||
$resultData['editData'] = $lastActionResult->getInputData();
|
||||
$renderData = array_merge($renderData, $resultData);
|
||||
}
|
||||
|
||||
return $this->view->render($response, 'account_edit.html.twig', $renderData);
|
||||
|
|
@ -109,20 +93,25 @@ class AccountController extends BaseController
|
|||
|
||||
public function editAccount(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
// Parse URL arguments and form data
|
||||
// Parse URL arguments
|
||||
$accountId = (int)$args['id'];
|
||||
|
||||
// Parse form data
|
||||
$editData = $request->getParsedBody();
|
||||
$errorMessage = null;
|
||||
|
||||
try {
|
||||
// Validate input
|
||||
$validatedEditData = AccountEditData::createFromArray($editData);
|
||||
$this->accountHandler->editAccountData($accountId, $validatedEditData);
|
||||
|
||||
// Save success result
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createSuccessResult('Account data was saved.'));
|
||||
} catch (InputValidationError $e) {
|
||||
// Save error result
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createErrorResult($e->getMessage(), $editData));
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
if (empty($errorMessage)) {
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createSuccessResult('Account data was saved.'));
|
||||
} else {
|
||||
$this->sessionHelper->setLastActionResult(ActionResult::createErrorResult($errorMessage, $editData));
|
||||
}
|
||||
|
||||
// Redirect to edit form page via GET (PRG)
|
||||
|
|
@ -138,7 +127,14 @@ class AccountController extends BaseController
|
|||
$accountId = (int)$args['id'];
|
||||
|
||||
// Get account data and list of aliases from database
|
||||
$renderData = $this->accountHandler->getAccountDataForDelete($accountId);
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
$aliases = $this->aliasRepository->fetchAliasesForUserId($accountId);
|
||||
|
||||
$renderData = [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'account_delete.html.twig', $renderData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Frontend\Accounts;
|
||||
|
||||
use MailAccountAdmin\Common\FormData;
|
||||
|
||||
class AccountCreateData extends FormData
|
||||
{
|
||||
private string $username;
|
||||
private string $password;
|
||||
private bool $active;
|
||||
private ?string $homeDir;
|
||||
private string $memo;
|
||||
|
||||
private function __construct(string $username, string $password, bool $active, ?string $homeDir, string $memo)
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->active = $active;
|
||||
$this->homeDir = $homeDir;
|
||||
$this->memo = $memo;
|
||||
}
|
||||
|
||||
public static function createFromArray($raw): self
|
||||
{
|
||||
return new self(
|
||||
self::validateUsername(trim($raw['username'] ?? '')),
|
||||
self::validatePassword(trim($raw['password'] ?? ''), trim($raw['password_repeat'] ?? '')),
|
||||
self::validateBoolOption(trim($raw['is_active'] ?? '')),
|
||||
self::validateHomeDir(trim($raw['home_dir'] ?? ''), false),
|
||||
self::validateMemo(trim($raw['memo'] ?? '')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function getHomeDir(): ?string
|
||||
{
|
||||
return $this->homeDir;
|
||||
}
|
||||
|
||||
public function getMemo(): string
|
||||
{
|
||||
return $this->memo;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace MailAccountAdmin\Frontend\Accounts;
|
||||
|
||||
use MailAccountAdmin\Common\FormData;
|
||||
use MailAccountAdmin\Exceptions\InputValidationError;
|
||||
|
||||
class AccountEditData extends FormData
|
||||
class AccountEditData
|
||||
{
|
||||
private ?string $username;
|
||||
private bool $usernameCreateAlias;
|
||||
|
|
@ -13,10 +13,10 @@ class AccountEditData extends FormData
|
|||
private ?string $password;
|
||||
private bool $active;
|
||||
private ?string $homeDir;
|
||||
private string $memo;
|
||||
private ?string $memo;
|
||||
|
||||
private function __construct(?string $username, bool $usernameCreateAlias, bool $usernameReplaceAlias, ?string $password, bool $active,
|
||||
?string $homeDir, string $memo)
|
||||
?string $homeDir, ?string $memo)
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->usernameCreateAlias = $usernameCreateAlias;
|
||||
|
|
@ -30,16 +30,70 @@ class AccountEditData extends FormData
|
|||
public static function createFromArray($raw): self
|
||||
{
|
||||
return new self(
|
||||
self::validateUsername(trim($raw['username'] ?? ''), false),
|
||||
self::validateUsername(trim($raw['username'] ?? '')),
|
||||
self::validateBoolOption(trim($raw['username_create_alias'] ?? '')),
|
||||
self::validateBoolOption(trim($raw['username_replace_alias'] ?? '')),
|
||||
self::validatePassword(trim($raw['password'] ?? ''), trim($raw['password_repeat'] ?? ''), false),
|
||||
self::validatePassword(trim($raw['password'] ?? ''), trim($raw['password_repeat'] ?? '')),
|
||||
self::validateBoolOption(trim($raw['is_active'] ?? '')),
|
||||
self::validateHomeDir(trim($raw['home_dir'] ?? ''), false),
|
||||
self::validateMemo(trim($raw['memo'] ?? '')),
|
||||
self::validateHomeDir(trim($raw['home_dir'] ?? '')),
|
||||
trim($raw['memo'] ?? '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Input validation
|
||||
|
||||
private static function validateUsername(string $username): ?string
|
||||
{
|
||||
if ($username === '') {
|
||||
return null;
|
||||
}
|
||||
if (strlen($username) > 100) {
|
||||
throw new InputValidationError('Username is too long.');
|
||||
}
|
||||
|
||||
$username = strtolower($username);
|
||||
if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+$/', $username) || preg_match('/^\\.|\\.\\.|\\.@|@\\.|\\.$/', $username)) {
|
||||
throw new InputValidationError('Username is not valid (must be a valid mail address).');
|
||||
}
|
||||
return $username;
|
||||
}
|
||||
|
||||
private static function validatePassword(string $password, string $passwordRepeat): ?string
|
||||
{
|
||||
if ($password === '') {
|
||||
return null;
|
||||
}
|
||||
if ($password !== $passwordRepeat) {
|
||||
throw new InputValidationError('Passwords do not match.');
|
||||
}
|
||||
return $password;
|
||||
}
|
||||
|
||||
private static function validateHomeDir(string $homeDir): ?string
|
||||
{
|
||||
if ($homeDir === '') {
|
||||
return null;
|
||||
}
|
||||
if (strlen($homeDir) > 100) {
|
||||
throw new InputValidationError('Home directory is too long.');
|
||||
}
|
||||
|
||||
$homeDir = trim($homeDir, '/');
|
||||
if (!preg_match('!^[a-z0-9._+-]+(/[a-z0-9._+-]+)*$!i', $homeDir)) {
|
||||
throw new InputValidationError('Home directory is not a valid path.');
|
||||
}
|
||||
return $homeDir;
|
||||
}
|
||||
|
||||
private static function validateBoolOption(string $raw): bool
|
||||
{
|
||||
return $raw !== '';
|
||||
}
|
||||
|
||||
|
||||
// Getters
|
||||
|
||||
public function getUsername(): ?string
|
||||
{
|
||||
return $this->username;
|
||||
|
|
|
|||
|
|
@ -8,21 +8,17 @@ use MailAccountAdmin\Exceptions\AccountNotFoundException;
|
|||
use MailAccountAdmin\Exceptions\InputValidationError;
|
||||
use MailAccountAdmin\Repositories\AccountRepository;
|
||||
use MailAccountAdmin\Repositories\AliasRepository;
|
||||
use MailAccountAdmin\Repositories\DomainRepository;
|
||||
|
||||
class AccountHandler
|
||||
{
|
||||
private AccountRepository $accountRepository;
|
||||
private AliasRepository $aliasRepository;
|
||||
private DomainRepository $domainRepository;
|
||||
private PasswordHelper $passwordHelper;
|
||||
|
||||
public function __construct(AccountRepository $accountRepository, AliasRepository $aliasRepository, DomainRepository $domainRepository,
|
||||
PasswordHelper $passwordHelper)
|
||||
public function __construct(AccountRepository $accountRepository, AliasRepository $aliasRepository, PasswordHelper $passwordHelper)
|
||||
{
|
||||
$this->accountRepository = $accountRepository;
|
||||
$this->aliasRepository = $aliasRepository;
|
||||
$this->domainRepository = $domainRepository;
|
||||
$this->passwordHelper = $passwordHelper;
|
||||
}
|
||||
|
||||
|
|
@ -63,59 +59,8 @@ class AccountHandler
|
|||
}
|
||||
|
||||
|
||||
// -- /accounts/new - Create new account
|
||||
|
||||
public function getPageDataForCreate(): array
|
||||
{
|
||||
return [
|
||||
'domainList' => array_keys($this->domainRepository->fetchDomainList()),
|
||||
];
|
||||
}
|
||||
|
||||
public function createNewAccount(AccountCreateData $createData): int
|
||||
{
|
||||
// Check if new username is still available
|
||||
$username = $createData->getUsername();
|
||||
if (!$this->accountRepository->checkUsernameAvailable($username) || !$this->aliasRepository->checkAliasAvailable($username)) {
|
||||
throw new InputValidationError("Username \"$username\" is not available.");
|
||||
}
|
||||
|
||||
// Hash new password
|
||||
$passwordHash = $this->passwordHelper->hashPassword($createData->getPassword());
|
||||
|
||||
// Construct home directory from username if necessary
|
||||
if ($createData->getHomeDir() !== null) {
|
||||
$homeDir = $createData->getHomeDir();
|
||||
} else {
|
||||
[$localPart, $domainPart] = explode('@', $username, 2);
|
||||
$homeDir = $domainPart . '/' . $localPart;
|
||||
}
|
||||
|
||||
// Create account in database
|
||||
return $this->accountRepository->insertAccount(
|
||||
$username,
|
||||
$passwordHash,
|
||||
$createData->getActive(),
|
||||
$homeDir,
|
||||
$createData->getMemo()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/{id}/edit - Edit account data
|
||||
|
||||
public function getAccountDataForEdit(int $accountId): array
|
||||
{
|
||||
// Get account data from database
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
|
||||
return [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'account' => $account,
|
||||
];
|
||||
}
|
||||
|
||||
public function editAccountData(int $accountId, AccountEditData $editData): void
|
||||
{
|
||||
// Check if account exists
|
||||
|
|
@ -199,22 +144,4 @@ class AccountHandler
|
|||
// Commit database transaction
|
||||
$this->accountRepository->commitTransaction();
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/{id}/delete - Delete account
|
||||
|
||||
public function getAccountDataForDelete(int $accountId): array
|
||||
{
|
||||
// Get account data from database
|
||||
$account = $this->accountRepository->fetchAccountById($accountId);
|
||||
|
||||
// Get list of aliases for this account
|
||||
$aliases = $this->aliasRepository->fetchAliasesForUserId($accountId);
|
||||
|
||||
return [
|
||||
'id' => $accountId,
|
||||
'accountUsername' => $account->getUsername(),
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,27 +65,6 @@ class AccountRepository extends BaseRepository
|
|||
return $statement->rowCount() === 0;
|
||||
}
|
||||
|
||||
public function insertAccount(string $username, string $passwordHash, bool $active, string $homeDir, string $memo): int
|
||||
{
|
||||
$query = '
|
||||
INSERT INTO mail_users
|
||||
(username, password, is_active, home_dir, memo)
|
||||
VALUES
|
||||
(:username, :password, :is_active, :home_dir, :memo)
|
||||
';
|
||||
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute([
|
||||
'username' => $username,
|
||||
'password' => $passwordHash,
|
||||
'is_active' => $active ? '1' : '0',
|
||||
'home_dir' => $homeDir,
|
||||
'memo' => $memo,
|
||||
]);
|
||||
|
||||
return (int)$this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
public function updateAccountWithId(int $accountId, ?string $newUsername, ?string $newPasswordHash, bool $newActive,
|
||||
?string $newHomeDir, string $newMemo): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class Routes
|
|||
// Accounts
|
||||
$app->get('/accounts', AccountController::class . ':showAccounts');
|
||||
$app->get('/accounts/new', AccountController::class . ':showAccountCreate');
|
||||
$app->post('/accounts/new', AccountController::class . ':createAccount');
|
||||
$app->get('/accounts/{id:[1-9][0-9]*}', AccountController::class . ':showAccountDetails');
|
||||
$app->get('/accounts/{id:[1-9][0-9]*}/edit', AccountController::class . ':showAccountEdit');
|
||||
$app->post('/accounts/{id:[1-9][0-9]*}/edit', AccountController::class . ':editAccount');
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block title %}Create account{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Accounts</h2>
|
||||
|
||||
<p>
|
||||
<b>Actions:</b>
|
||||
<a href="/accounts">List accounts</a> |
|
||||
<span>Create account</span>
|
||||
</p>
|
||||
|
||||
<h3>Create new account</h3>
|
||||
|
||||
<form action="/accounts/new" method="POST">
|
||||
{{ include('includes/form_result_box.html.twig') }}
|
||||
|
||||
<div class="form_box">
|
||||
<h4>Username</h4>
|
||||
<p>
|
||||
This is the primary mail address of the account and the username to use for login.
|
||||
The domain is part of the username (e.g. "user@example.com").
|
||||
</p>
|
||||
<details>
|
||||
<summary>Show list of known domains</summary>
|
||||
<p>{{ domainList ? domainList | join(', ') : 'No domains exist yet.' }}</p>
|
||||
</details>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="create_username">Username:</label></td>
|
||||
<td><input id="create_username" name="username" value="{{ formData['username'] | default('') }}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<h4>Password</h4>
|
||||
<p>The password will be hashed using the current default hash algorithm.</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="create_password">New password:</label></td>
|
||||
<td><input type="password" id="create_password" name="password" value="{{ formData['password'] | default('') }}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="create_password_repeat">Repeat password:</label></td>
|
||||
<td><input type="password" id="create_password_repeat" name="password_repeat" value="{{ formData['password_repeat'] | default('') }}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<h4>Account status</h4>
|
||||
<table>
|
||||
<tr>
|
||||
<td>New account status:</td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="is_active" {{ formData is not defined or formData['is_active'] | default() ? 'checked' : '' }}/>
|
||||
Active
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<h4>Home directory</h4>
|
||||
<p><b>Note:</b> By default the home directory will be determined automatically from the username and domain. Only change this if you know what you're doing!</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Default home directory:</td>
|
||||
<td><span class="gray">/srv/vmail/</span><samp><domain.tld></samp>/<samp><local_part></samp></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="create_home_dir">Set custom home directory:</label></td>
|
||||
<td>
|
||||
<span class="gray">/srv/vmail/</span><input id="create_home_dir" name="home_dir" value="{{ formData['home_dir'] | default('') }}"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<h4><label for="create_memo">Admin memo</label></h4>
|
||||
<p>This field is only readable by admins.</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="create_memo">Admin memo:</label></td>
|
||||
<td><textarea id="create_memo" name="memo" style="min-width: 40em;">{{ formData['memo'] | default('') }}</textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button type="submit">Create account</button>
|
||||
<button type="reset">Reset form</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
@ -16,11 +16,21 @@
|
|||
<h3>Edit account data</h3>
|
||||
|
||||
<form action="/accounts/{{ id }}/edit" method="POST">
|
||||
{{ include('includes/form_result_box.html.twig') }}
|
||||
{% if success is defined %}
|
||||
<div class="success_box">
|
||||
<h4>Success</h4>
|
||||
{{ success }}
|
||||
</div>
|
||||
{% elseif error is defined %}
|
||||
<div class="error_box">
|
||||
<h4>Error</h4>
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<input type="hidden" name="user_id" value="{{ id }}"/>
|
||||
|
||||
<div class="form_box">
|
||||
<div class="edit_box">
|
||||
<h4>Username</h4>
|
||||
<table>
|
||||
<tr>
|
||||
|
|
@ -29,12 +39,12 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td><label for="edit_username">New username:</label></td>
|
||||
<td><input id="edit_username" name="username" value="{{ formData['username'] | default('') }}"/></td>
|
||||
<td><input id="edit_username" name="username" value="{{ editData['username'] | default('') }}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<label>
|
||||
<input type="checkbox" name="username_create_alias" {{ formData['username_create_alias'] | default('') ? 'checked' : '' }}/>
|
||||
<input type="checkbox" name="username_create_alias" {{ editData['username_create_alias'] | default('') ? 'checked' : '' }}/>
|
||||
Create alias for old username
|
||||
</label>
|
||||
</td>
|
||||
|
|
@ -42,7 +52,7 @@
|
|||
<tr>
|
||||
<td colspan="2">
|
||||
<label>
|
||||
<input type="checkbox" name="username_replace_alias" {{ formData['username_replace_alias'] | default('') ? 'checked' : '' }}/>
|
||||
<input type="checkbox" name="username_replace_alias" {{ editData['username_replace_alias'] | default('') ? 'checked' : '' }}/>
|
||||
Replace existing alias
|
||||
</label>
|
||||
</td>
|
||||
|
|
@ -50,22 +60,22 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<div class="edit_box">
|
||||
<h4>Password</h4>
|
||||
<p>The new password will be hashed using the current default hash algorithm.</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="edit_password">New password:</label></td>
|
||||
<td><input type="password" id="edit_password" name="password" value="{{ formData['password'] | default('') }}"/></td>
|
||||
<td><input type="password" id="edit_password" name="password" value="{{ editData['password'] | default('') }}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="edit_password_repeat">Repeat password:</label></td>
|
||||
<td><input type="password" id="edit_password_repeat" name="password_repeat" value="{{ formData['password_repeat'] | default('') }}"/></td>
|
||||
<td><input type="password" id="edit_password_repeat" name="password_repeat" value="{{ editData['password_repeat'] | default('') }}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<div class="edit_box">
|
||||
<h4>Account status</h4>
|
||||
<table>
|
||||
<tr>
|
||||
|
|
@ -77,8 +87,8 @@
|
|||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="is_active"
|
||||
{%- if formData | default() -%}
|
||||
{{ formData['is_active'] | default() ? ' checked' : '' }}
|
||||
{%- if editData | default() -%}
|
||||
{{ editData['is_active'] ? ' checked' : '' }}
|
||||
{%- else -%}
|
||||
{{ account.isActive() ? ' checked' : '' }}
|
||||
{%- endif -%}
|
||||
|
|
@ -89,7 +99,7 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<div class="edit_box">
|
||||
<h4>Home directory</h4>
|
||||
<p><b>Important:</b> Changing the home directory here will <b>NOT</b> move any existing mail data, this needs to be done
|
||||
manually!</p>
|
||||
|
|
@ -101,19 +111,19 @@
|
|||
<tr>
|
||||
<td><label for="edit_home_dir">New home directory:</label></td>
|
||||
<td>
|
||||
<span class="gray">/srv/vmail/</span><input id="edit_home_dir" name="home_dir" value="{{ formData['home_dir'] | default('') }}"/>
|
||||
<span class="gray">/srv/vmail/</span><input id="edit_home_dir" name="home_dir" value="{{ editData['home_dir'] | default('') }}"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form_box">
|
||||
<div class="edit_box">
|
||||
<h4><label for="edit_memo">Admin memo</label></h4>
|
||||
<p>This field is only readable by admins.</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="edit_memo">Admin memo:</label></td>
|
||||
<td><textarea id="edit_memo" name="memo" style="min-width: 40em;">{{ formData | default() ? formData['memo'] : account.getMemo() }}</textarea></td>
|
||||
<td><textarea id="edit_memo" name="memo" style="min-width: 40em;">{{ editData | default() ? editData['memo'] : account.getMemo() }}</textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
<p>
|
||||
<b>Actions:</b>
|
||||
<span>List accounts</span> |
|
||||
<a href="/accounts/new">Create account</a>
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
{% if success is defined %}
|
||||
<div class="success_box">
|
||||
<h4>Success</h4>
|
||||
{{ success | raw }}
|
||||
</div>
|
||||
{% elseif error is defined %}
|
||||
<div class="error_box">
|
||||
<h4>Error</h4>
|
||||
{{ error | raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
Loading…
Reference in New Issue