diff --git a/php/public/forms.js b/php/public/forms.js index 029dfd5d..ac84c7d0 100644 --- a/php/public/forms.js +++ b/php/public/forms.js @@ -20,8 +20,10 @@ if (xhr.status === 201) { window.location.replace(xhr.getResponseHeader('Location')); } else if (xhr.status === 422) { + disableSpinner() showError(xhr.response); } else if (xhr.status === 500) { + disableSpinner() showError("Server error. Please check the mastercontainer logs for details."); } else { // If the responose is not one of the above, we should reload to show the latest content @@ -29,16 +31,12 @@ } } - function disable(element) { + function disableSpinnerSpinner() { document.getElementById('overlay').classList.add('loading'); - element.classList.add('loading'); - element.disabled = true; } - function enable(element) { + function disableSpinner() { document.getElementById('overlay').classList.remove('loading'); - element.classList.remove('loading'); - element.disabled = false; } function initForm(form) { @@ -50,11 +48,10 @@ var xhr = new XMLHttpRequest(); xhr.addEventListener('load', handleEvent); xhr.addEventListener('error', () => showError("Failed to talk to server.")); - xhr.addEventListener('load', () => enable(event.submitter)); - xhr.addEventListener('error', () => enable(event.submitter)); + xhr.addEventListener('error', () => disableSpinner()); xhr.open(form.method, form.getAttribute("action")); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - disable(event.submitter); + disableSpinnerSpinner(); xhr.send(new URLSearchParams(new FormData(form))); event.preventDefault(); } diff --git a/php/src/Controller/LoginController.php b/php/src/Controller/LoginController.php index 81b1ab84..954cf494 100644 --- a/php/src/Controller/LoginController.php +++ b/php/src/Controller/LoginController.php @@ -21,15 +21,17 @@ class LoginController public function TryLogin(Request $request, Response $response, array $args) : Response { if (!$this->dockerActionManager->isLoginAllowed()) { - return $response->withHeader('Location', '/')->withStatus(302); + $response->getBody()->write("The login is blocked since Nextcloud is running."); + return $response->withHeader('Location', '/')->withStatus(422); } $password = $request->getParsedBody()['password'] ?? ''; if($this->authManager->CheckCredentials($password)) { $this->authManager->SetAuthState(true); - return $response->withHeader('Location', '/')->withStatus(302); + return $response->withHeader('Location', '/')->withStatus(201); } - return $response->withHeader('Location', '/')->withStatus(302); + $response->getBody()->write("The password is false."); + return $response->withHeader('Location', '/')->withStatus(422); } public function GetTryLogin(Request $request, Response $response, array $args) : Response { diff --git a/php/templates/login.twig b/php/templates/login.twig index 1b3f746e..5659c4db 100644 --- a/php/templates/login.twig +++ b/php/templates/login.twig @@ -7,7 +7,7 @@

Nextcloud AIO Login

{% if is_login_allowed == true %}

Log in using your Nextcloud AIO password:

-
+