core: use postinit status code

This commit is contained in:
2024-01-08 20:57:43 +01:00
parent 6f9903e309
commit 476ed0b833
12 changed files with 87 additions and 89 deletions

View File

@ -100,14 +100,17 @@ class Client
async _update_logged(state)
{
if (!this.logged && state)
if (this.logged == state)
return;
if (state)
{
this.me = new MyProfile(this);
await this.me.init();
}
if (this.logged && !state)
else
{
navigateTo("/login");
this.me = undefined;
}
this.logged = state;
}
@ -115,13 +118,13 @@ class Client
async login(username, password)
{
let response = await this._post("/api/accounts/login", {username: username, password: password})
let data = await response.json();
if (data.id != undefined)
{
await this._update_logged(true);
return null;
}
return data;
if (response.status != 200)
return response.status;
this._update_logged(true);
return 0;
}
async logout()
@ -133,11 +136,9 @@ class Client
async _test_logged()
{
let response = await this._get("/api/accounts/logged");
let data = await response.json();
if (data.id !== undefined)
await this._update_logged(true);
return data.id !== undefined;
await this._update_logged(response.status === 200);
return response.status === 200
}
}