From 7859ef77ee23aefefd7e8c1ee5132dee3a17f27d Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sat, 31 Jul 2021 00:34:35 +0200 Subject: [PATCH] Accounts: Add edit and delete pages; implement forms (no real actions yet) --- public/static/style.css | 39 ++++--- src/Frontend/Accounts/AccountController.php | 54 +++++++++ src/Routes.php | 7 +- templates/account_delete.html.twig | 44 ++++++++ templates/account_details.html.twig | 9 +- templates/account_edit.html.twig | 115 ++++++++++++++++++++ templates/accounts.html.twig | 9 +- templates/domains.html.twig | 2 +- templates/login.html.twig | 2 +- 9 files changed, 258 insertions(+), 23 deletions(-) create mode 100644 templates/account_delete.html.twig create mode 100644 templates/account_edit.html.twig diff --git a/public/static/style.css b/public/static/style.css index 32af1ae..f4cf7bd 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -86,12 +86,8 @@ main.login_page { border: 1px solid #666666; } -main.login_page table td { - padding: 0.2em; -} - /* --- Text and other styling --- */ -h2 { +h2, h4 { margin: 0 0 0.5em 0; } @@ -105,9 +101,9 @@ a:hover, a:focus { text-decoration: underline; } -.error { +.error_box { background: #ff4444; - width: 30em; + max-width: 50em; margin: 1em 0; padding: 1em; } @@ -134,7 +130,14 @@ button { /* --- Tables --- */ -table, tr, td, th { +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; @@ -144,17 +147,15 @@ table, tr, td, th { text-align: left; } -/* --- Filter options --- */ -.filter_options { +/* --- Boxes --- */ +.filter_options, +.edit_box, +.confirmation_box { 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; @@ -163,3 +164,13 @@ 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/Frontend/Accounts/AccountController.php b/src/Frontend/Accounts/AccountController.php index 3904d61..1a27498 100644 --- a/src/Frontend/Accounts/AccountController.php +++ b/src/Frontend/Accounts/AccountController.php @@ -70,4 +70,58 @@ class AccountController extends BaseController 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/Routes.php b/src/Routes.php index 57a0b87..728e70e 100644 --- a/src/Routes.php +++ b/src/Routes.php @@ -26,8 +26,11 @@ class Routes // 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 . ':showAccountDetails'); - $app->get('/accounts/{id:[1-9][0-9]*}/delete', 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'); } } diff --git a/templates/account_delete.html.twig b/templates/account_delete.html.twig new file mode 100644 index 0000000..7a4840a --- /dev/null +++ b/templates/account_delete.html.twig @@ -0,0 +1,44 @@ +{% extends "base.html.twig" %} + +{% block title %}Delete account{% endblock %} + +{% block content %} +

Account: {{ accountUsername }}

+ +

+ Actions: + View | + Edit | + Delete | + Send mail +

+ +

Delete account

+ +

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 %} +
+

Error:

+ {{ error }} +
+ {% endif %} + +
+

Please confirm that you want to delete this account by entering your password.

+
+

+ + +

+ +
+
+{% endblock %} diff --git a/templates/account_details.html.twig b/templates/account_details.html.twig index 1dba4dd..ec702fe 100644 --- a/templates/account_details.html.twig +++ b/templates/account_details.html.twig @@ -1,18 +1,21 @@ {% extends "base.html.twig" %} -{% block title %}Accounts{% endblock %} +{% block title %}View account{% endblock %} {% block content %}

Account: {{ accountUsername }}

Actions: + View | Edit | Delete | Send mail

- +

View account details

+ +
@@ -62,7 +65,7 @@

Aliases

{% if aliases %} -
User ID {{ accountData['user_id'] }}
+
diff --git a/templates/account_edit.html.twig b/templates/account_edit.html.twig new file mode 100644 index 0000000..4667eef --- /dev/null +++ b/templates/account_edit.html.twig @@ -0,0 +1,115 @@ +{% extends "base.html.twig" %} + +{% block title %}Edit account{% endblock %} + +{% block content %} +

Account: {{ accountUsername }}

+ +

+ Actions: + View | + Edit | + Delete | + Send mail +

+ +

Edit account data

+ + + {% if error is defined %} +
+

Error

+ {{ error }} +
+ {% endif %} + +
+

Username

+
Address Created at
+ + + + + + + + + + + + + + +
Current username:{{ accountData['username'] }}
+ +
+ +
+ + +
+

Password

+

The new password will be hashed using the current default hash algorithm.

+ + + + + + + + + +
+
+ +
+

Account status

+ + + + + + + + + +
Current status:{{ accountData['is_active'] == '1' ? 'Active' : 'Inactive' }}
New status: + +
+
+ +
+

Home directory

+

Important: Changing the home directory here will NOT move any existing mail data, this needs to be done + manually!

+ + + + + + + + + +
Current home directory:/srv/vmail/{{ accountData['home_dir'] }}
+ /srv/vmail/ +
+
+ +
+

+

This field is only readable by admins.

+ + + + + +
+
+ + + + +{% endblock %} diff --git a/templates/accounts.html.twig b/templates/accounts.html.twig index b920b3b..3c9ae7f 100644 --- a/templates/accounts.html.twig +++ b/templates/accounts.html.twig @@ -5,7 +5,12 @@ {% block content %}

Accounts

-

List of all mail accounts.

+

+ Actions: + Create account +

+ +

List of accounts

@@ -19,7 +24,7 @@ - +
diff --git a/templates/domains.html.twig b/templates/domains.html.twig index 79d0044..998e7ab 100644 --- a/templates/domains.html.twig +++ b/templates/domains.html.twig @@ -7,7 +7,7 @@

This is a list of all domains auto-generated from the existing mail accounts and aliases. As such it is read-only.

-
Username Domain
+
diff --git a/templates/login.html.twig b/templates/login.html.twig index 07fafb6..ffe297e 100644 --- a/templates/login.html.twig +++ b/templates/login.html.twig @@ -18,7 +18,7 @@ {% if error is defined %} -
{{ error }}
+
{{ error }}
{% endif %}
Domain Accounts