add: profile avatar

This commit is contained in:
2023-12-06 15:19:41 +01:00
parent 910644a804
commit 9b6c5547f0
16 changed files with 141 additions and 37 deletions

View File

@ -1,4 +1,5 @@
import { Account } from "./account.js";
import { Profile } from "./profile.js";
function getCookie(name)
{
@ -73,12 +74,26 @@ class Client
return response;
}
async _patch_file(uri, file)
{
let response = await fetch(this._url + uri, {
method: "PATCH",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
},
body: file,
});
return response;
}
async login(username, password)
{
let response = await this._post("/api/accounts/login", {username: username, password: password})
let data = await response.json();
if (data == "user connected")
if (data.id != undefined)
{
this.me = new Profile(this)
await this.me.init(data.id)
this.logged = true;
return null;
}
@ -95,7 +110,13 @@ class Client
{
let response = await this._get("/api/accounts/logged");
let data = await response.json();
return data === "True";
if (data.id !== undefined)
{
this.me = new Profile(this)
await this.me.init(data.id)
}
return data.id !== undefined;
}
}