diff --git a/public/static/style.css b/public/static/style.css index f4cf7bd..ab04854 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -86,8 +86,12 @@ main.login_page { border: 1px solid #666666; } +main.login_page table td { + padding: 0.2em; +} + /* --- Text and other styling --- */ -h2, h4 { +h2 { margin: 0 0 0.5em 0; } @@ -101,9 +105,9 @@ a:hover, a:focus { text-decoration: underline; } -.error_box { +.error { background: #ff4444; - max-width: 50em; + width: 30em; margin: 1em 0; padding: 1em; } @@ -112,50 +116,31 @@ a:hover, a:focus { color: gray; } -.green { - color: green; -} - -.red { - color: red; -} - button { padding: 0.2em 1em; } +table, tr, td, th { + border: 1px solid #999999; + border-collapse: collapse; + padding: 0.25em 0.5em; +} + .inactive { color: gray; } -/* --- Tables --- */ - -table td, table th { - padding: 0.25em 0.5em; -} - -table.bordered_table, -table.bordered_table tr, -table.bordered_table td, -table.bordered_table th { - border: 1px solid #999999; - border-collapse: collapse; - padding: 0.25em 0.5em; -} - -.vertical_table_headers th { - text-align: left; -} - -/* --- Boxes --- */ -.filter_options, -.edit_box, -.confirmation_box { +/* --- Filter options --- */ +.filter_options { border: 1px solid #999999; padding: 1em; margin: 1em 0; } +.filter_options h4 { + margin: 0 0 0.5em 0; +} + /* --- Detail columns --- */ input#show_details_checkbox { margin-bottom: 1em; @@ -164,13 +149,3 @@ input#show_details_checkbox { input#show_details_checkbox:not(:checked) ~ table .detail_column { display: none; } - -/* --- Edit box --- */ -.edit_box p:last-child { - margin-bottom: 0; -} - -/* --- Confirmation box --- */ -.confirmation_box p:first-child { - margin-top: 0; -} diff --git a/src/Dependencies.php b/src/Dependencies.php index 50c82e1..f7f9742 100644 --- a/src/Dependencies.php +++ b/src/Dependencies.php @@ -11,7 +11,6 @@ use MailAccountAdmin\Frontend\Login\LoginController; use MailAccountAdmin\Frontend\Dashboard\DashboardController; use MailAccountAdmin\Repositories\AccountRepository; use MailAccountAdmin\Repositories\AdminUserRepository; -use MailAccountAdmin\Repositories\AliasRepository; use MailAccountAdmin\Repositories\DomainRepository; use PDO; use Psr\Container\ContainerInterface; @@ -71,11 +70,6 @@ class Dependencies $c->get(self::DATABASE), ); }); - $container->set(AliasRepository::class, function (ContainerInterface $c) { - return new AliasRepository( - $c->get(self::DATABASE), - ); - }); // Helper classes $container->set(UserHelper::class, function (ContainerInterface $c) { @@ -110,7 +104,6 @@ class Dependencies $c->get(self::TWIG), $c->get(UserHelper::class), $c->get(AccountRepository::class), - $c->get(AliasRepository::class), ); }); diff --git a/src/Exceptions/AccountNotFoundException.php b/src/Exceptions/AccountNotFoundException.php deleted file mode 100644 index 4c9833b..0000000 --- a/src/Exceptions/AccountNotFoundException.php +++ /dev/null @@ -1,8 +0,0 @@ -accountRepository = $accountRepository; - $this->aliasRepository = $aliasRepository; } public function showAccounts(Request $request, Response $response): Response @@ -38,90 +34,4 @@ class AccountController extends BaseController return $this->view->render($response, 'accounts.html.twig', $renderData); } - - public function showAccountDetails(Request $request, Response $response, array $args): Response - { - // Parse URL arguments - $accountId = (int)$args['id']; - - // Get account data from database - $accountData = $this->accountRepository->fetchAccountById($accountId); - $accountUsername = $accountData['username']; - $accountData['domain'] = explode('@', $accountUsername, 2)[1]; - - // Don't display the password hash, but at least the type of hash (used hash algorithm) - if ($accountData['password'] === '') { - $passwordHashType = 'empty'; - } else { - $passwordHashInfo = password_get_info($accountData['password']); - $passwordHashType = $passwordHashInfo['algoName'] ?? 'unknown'; - } - - // Get list of aliases for this account - $aliases = $this->aliasRepository->fetchAliasesForUserId($accountId); - - $renderData = [ - 'id' => $accountId, - 'accountUsername' => $accountUsername, - 'accountData' => $accountData, - 'passwordHashType' => $passwordHashType, - 'aliases' => $aliases, - ]; - - return $this->view->render($response, 'account_details.html.twig', $renderData); - } - - public function showAccountCreate(Request $request, Response $response): Response - { - return $this->showAccounts($request, $response); - } - - public function showAccountEdit(Request $request, Response $response, array $args): Response - { - // Parse URL arguments - $accountId = (int)$args['id']; - - // Get account data from database - $accountData = $this->accountRepository->fetchAccountById($accountId); - - $renderData = [ - 'id' => $accountId, - 'accountUsername' => $accountData['username'], - 'accountData' => $accountData, - ]; - - return $this->view->render($response, 'account_edit.html.twig', $renderData); - } - - public function editAccount(Request $request, Response $response, array $args): Response - { - // TODO: just a placeholder - $this->view->getEnvironment()->addGlobal('error', 'Not implemented yet!'); - return $this->showAccountEdit($request, $response, $args); - } - - public function showAccountDelete(Request $request, Response $response, array $args): Response - { - // Parse URL arguments - $accountId = (int)$args['id']; - - // Get account data and list of aliases from database - $accountData = $this->accountRepository->fetchAccountById($accountId); - $aliases = $this->aliasRepository->fetchAliasesForUserId($accountId); - - $renderData = [ - 'id' => $accountId, - 'accountUsername' => $accountData['username'], - 'aliases' => $aliases, - ]; - - return $this->view->render($response, 'account_delete.html.twig', $renderData); - } - - public function deleteAccount(Request $request, Response $response, array $args): Response - { - // TODO: just a placeholder - $this->view->getEnvironment()->addGlobal('error', 'Not implemented yet!'); - return $this->showAccountDelete($request, $response, $args); - } } diff --git a/src/Repositories/AccountRepository.php b/src/Repositories/AccountRepository.php index a506447..a97e3cd 100644 --- a/src/Repositories/AccountRepository.php +++ b/src/Repositories/AccountRepository.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace MailAccountAdmin\Repositories; -use MailAccountAdmin\Exceptions\AccountNotFoundException; use PDO; class AccountRepository extends BaseRepository @@ -33,16 +32,4 @@ class AccountRepository extends BaseRepository $statement->execute($queryParams); return $statement->fetchAll(PDO::FETCH_ASSOC); } - - public function fetchAccountById(int $accountId): array - { - $statement = $this->pdo->prepare('SELECT * FROM mail_users WHERE user_id = :user_id LIMIT 1'); - $statement->execute(['user_id' => $accountId]); - - if ($statement->rowCount() < 1) { - throw new AccountNotFoundException("Account with user ID '$accountId' was not found."); - } - - return $statement->fetch(PDO::FETCH_ASSOC); - } } diff --git a/src/Repositories/AliasRepository.php b/src/Repositories/AliasRepository.php deleted file mode 100644 index ac212c2..0000000 --- a/src/Repositories/AliasRepository.php +++ /dev/null @@ -1,16 +0,0 @@ -pdo->prepare('SELECT * FROM mail_aliases WHERE user_id = :user_id ORDER BY mail_address'); - $statement->execute(['user_id' => $userId]); - return $statement->fetchAll(PDO::FETCH_ASSOC); - } -} diff --git a/src/Routes.php b/src/Routes.php index 728e70e..03e0b4a 100644 --- a/src/Routes.php +++ b/src/Routes.php @@ -23,14 +23,10 @@ class Routes // Domains $app->get('/domains', DomainController::class . ':showDomains'); + $app->get('/domains/{foo}', DomainController::class . ':showDomains'); // Accounts $app->get('/accounts', AccountController::class . ':showAccounts'); - $app->get('/accounts/new', AccountController::class . ':showAccountCreate'); - $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'); - $app->get('/accounts/{id:[1-9][0-9]*}/delete', AccountController::class . ':showAccountDelete'); - $app->post('/accounts/{id:[1-9][0-9]*}/delete', AccountController::class . ':deleteAccount'); + $app->get('/accounts/{foo}', AccountController::class . ':showAccounts'); } } diff --git a/templates/account_delete.html.twig b/templates/account_delete.html.twig deleted file mode 100644 index 7a4840a..0000000 --- a/templates/account_delete.html.twig +++ /dev/null @@ -1,44 +0,0 @@ -{% extends "base.html.twig" %} - -{% block title %}Delete account{% endblock %} - -{% block content %} -
- Actions: - View | - Edit | - Delete | - Send mail -
- -You are about to delete the mail account "{{ accountUsername }}" including the following aliases:
-Note: This will only delete the user entry from the database. Mail data will not be deleted!
- - {% if error is defined %} -Please confirm that you want to delete this account by entering your password.
- -- Actions: - View | - Edit | - Delete | - Send mail -
- -| User ID | -{{ accountData['user_id'] }} | -
|---|---|
| Username | -{{ accountData['username'] }} | -
| Domain | -{{ accountData['domain'] }} | -
| Password | -- {% if passwordHashType == 'empty' %} - [No password set] - {% elseif passwordHashType == 'unknown' %} - [Not hashed / unknown hash algorithm] - {% else %} - [{{ passwordHashType }} hash] - {% endif %} - | -
| Status | -{{ accountData['is_active'] == '1' ? 'Active' : 'Inactive' }} | -
| Home directory | -/srv/vmail/{{ accountData['home_dir'] }} | -
| Admin memo | -{{ accountData['memo'] | nl2br }} | -
| Created at | -{{ accountData['created_at'] }} | -
| Last modified at | -{{ accountData['modified_at'] }} | -
| Address | -Created at | -Actions | -
|---|---|---|
| {{ alias['mail_address'] }} | -{{ alias['created_at'] }} | -Delete | {# TODO #} -
No aliases.
- {% endif %} -{% endblock %} diff --git a/templates/account_edit.html.twig b/templates/account_edit.html.twig deleted file mode 100644 index 4667eef..0000000 --- a/templates/account_edit.html.twig +++ /dev/null @@ -1,115 +0,0 @@ -{% extends "base.html.twig" %} - -{% block title %}Edit account{% endblock %} - -{% block content %} -- Actions: - View | - Edit | - Delete | - Send mail -
- -- Actions: - Create account -
- -List of all mail accounts.