From 44b257a2b54ed2e8fb43186586f75085fc8c5032 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Apr 2026 16:36:06 +0000 Subject: [PATCH] feat: show deSEC password field only after email-already-registered failure, via POST /containers and Twig (no sessions, no query params) Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/9eadc186-a642-409b-871d-f2bbb47f20ce Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com> --- php/public/index.php | 43 ++++++++++++++++++-- php/src/Desec/AlreadyRegisteredException.php | 17 ++++++++ php/src/Desec/DesecManager.php | 5 +-- php/templates/includes/desec-register.twig | 16 +++++--- 4 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 php/src/Desec/AlreadyRegisteredException.php diff --git a/php/public/index.php b/php/public/index.php index 9d34eabd..f2ee97c9 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -112,7 +112,13 @@ $app->post('/api/configuration', \AIO\Controller\ConfigurationController::class $app->post('/api/desec/register', \AIO\Controller\DesecController::class . ':Register'); // Views -$app->get('/containers', function (Request $request, Response $response, array $args) use ($container) { +// Shared closure that renders the containers page. +// $desecVars can override 'desec_show_password', 'desec_prefill_email', and 'desec_error'. +$renderContainersPage = function ( + Response $response, + Request $request, + array $desecVars = [], +) use ($container): Response { $view = Twig::fromRequest($request); $view->addExtension(new \AIO\Twig\ClassExtension()); /** @var \AIO\Data\ConfigurationManager $configurationManager */ @@ -130,7 +136,7 @@ $app->get('/containers', function (Request $request, Response $response, array $ $bypass_container_update = isset($params['bypass_container_update']); $skip_domain_validation = isset($params['skip_domain_validation']); - return $view->render($response, 'containers.twig', [ + return $view->render($response, 'containers.twig', array_merge([ 'domain' => $configurationManager->domain, 'apache_port' => $configurationManager->apachePort, 'borg_backup_host_location' => $configurationManager->borgBackupHostLocation, @@ -185,8 +191,39 @@ $app->get('/containers', function (Request $request, Response $response, array $ 'desec_password' => $configurationManager->desecPassword, 'is_desec_domain' => $configurationManager->isDesecDomain(), 'desec_account_registered' => $configurationManager->isDesecAccountRegistered(), - ]); + 'desec_show_password' => false, + 'desec_prefill_email' => '', + 'desec_error' => '', + ], $desecVars)); +}; + +$app->get('/containers', function (Request $request, Response $response, array $args) use ($renderContainersPage): Response { + return $renderContainersPage($response, $request); })->setName('profile'); + +$app->post('/containers', function (Request $request, Response $response, array $args) use ($container, $renderContainersPage): Response { + $email = (string)($request->getParsedBody()['desec_email'] ?? ''); + $slug = (string)($request->getParsedBody()['desec_slug'] ?? ''); + $password = (string)($request->getParsedBody()['desec_password'] ?? ''); + + /** @var \AIO\Desec\DesecManager $desecManager */ + $desecManager = $container->get(\AIO\Desec\DesecManager::class); + try { + $desecManager->register($email, $slug, $password); + return $response->withStatus(303)->withHeader('Location', '/containers'); + } catch (\AIO\Desec\AlreadyRegisteredException $ex) { + return $renderContainersPage($response, $request, [ + 'desec_show_password' => true, + 'desec_prefill_email' => $email, + 'desec_error' => $ex->getMessage(), + ]); + } catch (\Exception $ex) { + return $renderContainersPage($response, $request, [ + 'desec_prefill_email' => $email, + 'desec_error' => $ex->getMessage(), + ]); + } +}); $app->get('/login', function (Request $request, Response $response, array $args) use ($container) { $view = Twig::fromRequest($request); /** @var \AIO\Docker\DockerActionManager $dockerActionManager */ diff --git a/php/src/Desec/AlreadyRegisteredException.php b/php/src/Desec/AlreadyRegisteredException.php new file mode 100644 index 00000000..54ce2ee2 --- /dev/null +++ b/php/src/Desec/AlreadyRegisteredException.php @@ -0,0 +1,17 @@ +Your deSEC account ({{ desec_email }}) was registered successfully but the domain could not be registered. Please enter a desired subdomain slug (the part before .dedyn.io) and try again, or leave it blank for a random one.

Your deSEC login credentials (for desec.io): Email: {{ desec_email }}.

Reveal deSEC password{{ desec_password }}
. Please save these in a safe place.

-
+ {% if desec_error %}

{{ desec_error }}

{% endif %} + @@ -12,12 +13,17 @@
{% else %}

Please enter your email address. You can also enter a desired subdomain slug (the part before .dedyn.io); leave it blank for a random one.

-

If you already have a deSEC account for this email address, enter your deSEC password in the optional password field below to log in with it instead of creating a new account.

-
+ {% if desec_show_password %} +

If you already have a deSEC account for this email address, enter your deSEC password in the optional password field below to log in with it instead of creating a new account.

+ {% endif %} + {% if desec_error %}

{{ desec_error }}

{% endif %} + - - + + {% if desec_show_password %} + + {% endif %}