tentative de merge

This commit is contained in:
2023-12-16 18:00:38 +01:00
parent 86e2528d04
commit 51354d9922
12 changed files with 154 additions and 118 deletions

View File

@ -0,0 +1,19 @@
import { Profile } from "./profile.js";
class MyProfile extends Profile
{
async change_avatar(form_data)
{
let response = await this.client._patch_file(`/api/profiles/me`, form_data);
let response_data = await response.json()
return response_data;
}
async init()
{
super.init("me");
}
}
export {MyProfile}

View File

@ -1,7 +1,15 @@
import { Client } from "./client.js";
class Account
{
/**
* @param {Client} client
*/
constructor (client)
{
/**
* @type {Client} client
*/
this.client = client;
}
@ -28,7 +36,6 @@ class Account
this.client._logged = false;
return null;
}
console.log(response_data)
if (response_data == "user deleted")
this.client._logged = false;
return response_data;
@ -55,7 +62,7 @@ class Account
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
{
this.client._logged = false;
this.client._;
return null;
}
return response_data;

View File

@ -1,8 +1,8 @@
import { Account } from "./account.js";
import { MatchMaking } from "./matchmaking.js";
import { Profile } from "./profile.js";
import { Profiles } from "./profiles.js";
import { Channels } from './chat/channels.js';
import { MyProfile } from "./MyProfile.js";
function getCookie(name)
{
@ -94,15 +94,23 @@ class Client
return response;
}
async _update_logged(state)
{
if (this.logged && state)
{
this.me = new MyProfile(this);
await this.me.init();
}
this.logged = state;
}
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)
{
this.me = new Profile(this)
await this.me.init(data.id)
this.logged = true;
await this._update_logged(true);
return null;
}
return data;
@ -111,7 +119,7 @@ class Client
async logout()
{
await this._get("/api/accounts/logout");
this.logged = false;
await this._update_logged(false);
}
async _test_logged()
@ -120,10 +128,7 @@ class Client
let data = await response.json();
if (data.id !== undefined)
{
this.me = new Profile(this)
await this.me.init(data.id)
}
await this._update_logged(true);
return data.id !== undefined;
}
}

View File

@ -1,9 +1,9 @@
import { client, navigateTo } from "../index.js"
import { Client } from "./client.js";
class MatchMaking
{
/**
* @param {client} client
* @param {Client} client
*/
constructor(client)
{

View File

@ -1,7 +1,15 @@
import { Client } from "./client.js";
class Profile
{
/**
* @param {Client} client
*/
constructor (client, username = undefined, avatar_url = undefined, user_id = undefined)
{
/**
* @type {Client} client
*/
this.client = client;
this.username = username;
this.avatar_url = avatar_url
@ -13,23 +21,10 @@ class Profile
let response = await this.client._get(`/api/profiles/${user_id}`);
let response_data = await response.json();
this.user_id = user_id;
this.user_id = response.user_id;
this.username = response_data.username;
this.avatar_url = response_data.avatar_url;
}
async change_avatar(form_data)
{
let response = await this.client._patch_file(`/api/profiles/${this.user_id}`, form_data);
let response_data = await response.json()
return response_data;
}
async setData (data)
{
}
}
export {Profile}

View File

@ -2,8 +2,14 @@ import { Profile } from "./profile.js";
class Profiles
{
/**
* @param {Client} client
*/
constructor (client)
{
/**
* @type {Client} client
*/
this.client = client
}