diff --git a/php/public/forms.js b/php/public/forms.js
index b37fdcdb..ec326b8c 100644
--- a/php/public/forms.js
+++ b/php/public/forms.js
@@ -16,13 +16,21 @@
setTimeout(toast.remove.bind(toast), 10000)
}
- function handleEvent(e) {
+ function handleEvent(e, form) {
const xhr = e.target;
if (xhr.status === 201) {
window.location.replace(xhr.getResponseHeader('Location'));
} else if (xhr.status === 422) {
disableSpinner()
showError(xhr.response);
+ if (form) {
+ const revealSelector = form.dataset.revealOnError;
+ const revealWhen = form.dataset.revealWhen;
+ if (revealSelector && (!revealWhen || xhr.response.includes(revealWhen))) {
+ const target = document.querySelector(revealSelector);
+ if (target) target.style.display = '';
+ }
+ }
} else if (xhr.status === 500) {
showError("Server error. Please check the mastercontainer logs for details. This page will reload after 10s automatically. Then you can check the mastercontainer logs.");
// Reload after 10s since it is expected that the updated view is shown (e.g. after starting containers)
@@ -50,7 +58,7 @@
lastError.remove()
}
let xhr = new XMLHttpRequest();
- xhr.addEventListener('load', handleEvent);
+ xhr.addEventListener('load', function(e) { handleEvent(e, form); });
xhr.addEventListener('error', () => showError("Failed to talk to server."));
xhr.addEventListener('error', () => disableSpinner());
xhr.open(form.method, form.getAttribute("action"));
diff --git a/php/public/index.php b/php/public/index.php
index 00e4c2a3..9d34eabd 100644
--- a/php/public/index.php
+++ b/php/public/index.php
@@ -185,11 +185,7 @@ $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' => (bool)($_SESSION['desec_show_password'] ?? false),
- 'desec_prefill_email' => (string)($_SESSION['desec_prefill_email'] ?? ''),
- 'desec_error' => (string)($_SESSION['desec_error'] ?? ''),
]);
- unset($_SESSION['desec_show_password'], $_SESSION['desec_prefill_email'], $_SESSION['desec_error']);
})->setName('profile');
$app->get('/login', function (Request $request, Response $response, array $args) use ($container) {
$view = Twig::fromRequest($request);
diff --git a/php/src/Controller/DesecController.php b/php/src/Controller/DesecController.php
index 82eb90b5..42f5c96d 100644
--- a/php/src/Controller/DesecController.php
+++ b/php/src/Controller/DesecController.php
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace AIO\Controller;
-use AIO\Desec\AlreadyRegisteredException;
use AIO\Desec\DesecManager;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@@ -15,23 +14,15 @@ readonly class DesecController {
}
public function Register(Request $request, Response $response, array $args): Response {
- $email = (string)($request->getParsedBody()['desec_email'] ?? '');
- $slug = (string)($request->getParsedBody()['desec_slug'] ?? '');
- $password = (string)($request->getParsedBody()['desec_password'] ?? '');
-
try {
+ $email = (string)($request->getParsedBody()['desec_email'] ?? '');
+ $slug = (string)($request->getParsedBody()['desec_slug'] ?? '');
+ $password = (string)($request->getParsedBody()['desec_password'] ?? '');
$this->desecManager->register($email, $slug, $password);
- } catch (AlreadyRegisteredException $ex) {
- $_SESSION['desec_show_password'] = true;
- $_SESSION['desec_prefill_email'] = $ex->email;
- $_SESSION['desec_error'] = $ex->getMessage();
+ return $response->withStatus(201)->withHeader('Location', '.');
} catch (\Exception $ex) {
- $_SESSION['desec_error'] = $ex->getMessage();
+ $response->getBody()->write($ex->getMessage());
+ return $response->withStatus(422);
}
-
- // Post/Redirect/Get: always redirect back to the containers page.
- // The browser follows the Location header and issues a fresh GET,
- // which prevents form-resubmission on reload.
- return $response->withStatus(303)->withHeader('Location', '../../containers');
}
}
diff --git a/php/src/Desec/AlreadyRegisteredException.php b/php/src/Desec/AlreadyRegisteredException.php
deleted file mode 100644
index aaa9a8b4..00000000
--- a/php/src/Desec/AlreadyRegisteredException.php
+++ /dev/null
@@ -1,20 +0,0 @@
-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 enter your email address. You can also enter a desired subdomain slug (the part before .dedyn.io); leave it blank for a random one.
{{ desec_error }}
- {% endif %} -