fix the login form

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2023-03-31 16:41:48 +02:00
parent c1595afe2d
commit 9954641e02
3 changed files with 12 additions and 13 deletions

View file

@ -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();
}

View file

@ -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 {

View file

@ -7,7 +7,7 @@
<h1>Nextcloud AIO Login</h1>
{% if is_login_allowed == true %}
<p>Log in using your Nextcloud AIO password:</p>
<form method="POST" action="/api/auth/login">
<form method="POST" action="/api/auth/login" class="xhr">
<input type="text" autocomplete="off" name="password" placeholder="Password" />
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">