fix: redirect to home after login

This commit is contained in:
AdrienLSH 2024-01-09 19:55:55 +01:00
parent 56d352fead
commit 8eb54d0f14
2 changed files with 13 additions and 16 deletions

View File

@ -34,8 +34,8 @@ class Client
async isAuthentificate()
{
if (this._logged == undefined)
this.logged = await this._test_logged();
return this.logged;
this._logged = await this._test_logged();
return this._logged;
}
async _get(uri, data)
@ -100,7 +100,7 @@ class Client
async _update_logged(state)
{
if (this.logged == state)
if (this._logged == state)
return;
if (state)
@ -112,19 +112,16 @@ class Client
{
this.me = undefined;
}
this.logged = state;
this._logged = state;
}
async login(username, password)
{
let response = await this._post("/api/accounts/login", {username: username, password: password})
if (response.status == 200)
await this._update_logged(true);
if (response.status != 200)
return response.status;
this._update_logged(true);
return 0;
}
async logout()

View File

@ -7,16 +7,16 @@ async function login()
let username = document.getElementById("username-input").value;
let password = document.getElementById("password-input").value;
console.log(client._logged);
let response_data = await client.login(username, password);
if (response_data == null)
{
if (response_data == 200) {
navigateTo("/home");
return;
}
} else {
//TODO: error field
clear("innerHTML", ["username", "user", "password"]);
fill_errors(response_data, "innerHTML");
}
}
export default class extends AbstractNonAuthentifiedView {