merge
This commit is contained in:
@ -48,41 +48,24 @@ class Account
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account data (username)
|
||||
* @returns {?Promise<Object>}
|
||||
*/
|
||||
async get()
|
||||
* @param {String} newUsername
|
||||
* @returns {?Promise<Object>}
|
||||
*/
|
||||
async updateUsername(newUsername)
|
||||
{
|
||||
let response = await this.client._get("/api/accounts/edit");
|
||||
let response_data = await response.json();
|
||||
const data = {
|
||||
username: newUsername
|
||||
};
|
||||
const response = await this.client._patch_json(`/api/accounts/update_profile`, data);
|
||||
const respondeData = await response.json();
|
||||
|
||||
if (response.status === 403)
|
||||
{
|
||||
this.client._update_logged(false);
|
||||
if (response.status === 200) {
|
||||
this.client.me.username = respondeData.username;
|
||||
document.getElementById('navbarDropdownButton').innerHTML = respondeData.username;
|
||||
document.getElementById('myProfileLink').href = '/profiles/' + respondeData.username;
|
||||
return null;
|
||||
}
|
||||
return response_data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} data
|
||||
* @param {Number} password
|
||||
* @returns {?Object}
|
||||
*/
|
||||
async update(data, password)
|
||||
{
|
||||
data.current_password = password;
|
||||
let response = await this.client._patch_json("/api/accounts/edit", data);
|
||||
let response_data = await response.json();
|
||||
|
||||
if (response.status === 403)
|
||||
{
|
||||
this.client._update_logged(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
return response_data;
|
||||
return respondeData['authorize'] || respondeData['detail'] || respondeData['username']?.join(' ') || 'Error.';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { MatchMaking } from "./Matchmaking.js";
|
||||
import { Profiles } from "./Profiles.js";
|
||||
import { Channels } from './chat/Channels.js';
|
||||
import { MyProfile } from "./MyProfile.js";
|
||||
import { navigateTo } from "../index.js";
|
||||
import { Tourmanents } from "./tournament/Tournaments.js";
|
||||
import { Notice } from "./chat/Notice.js";
|
||||
import { Channel } from "./chat/Channel.js";
|
||||
@ -97,6 +96,9 @@ class Client
|
||||
{
|
||||
let response = await fetch(this._url + uri, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Accept-Language': this.lang.currentLang
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return response;
|
||||
@ -135,7 +137,8 @@ class Client
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRFToken": getCookie("csrftoken"),
|
||||
},
|
||||
'Accept-Language': this.lang.currentLang,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return response;
|
||||
@ -154,7 +157,8 @@ class Client
|
||||
headers: {
|
||||
"X-CSRFToken": getCookie("csrftoken"),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
'Accept-Language': this.lang.currentLang,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return response;
|
||||
@ -172,7 +176,8 @@ class Client
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"X-CSRFToken": getCookie("csrftoken"),
|
||||
},
|
||||
'Accept-Language': this.lang.currentLang,
|
||||
},
|
||||
body: file,
|
||||
});
|
||||
return response;
|
||||
|
@ -14,15 +14,35 @@ class MyProfile extends Profile
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} form_data
|
||||
* @returns {Promise<Object>}
|
||||
* @param {File} selectedFile
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
async change_avatar(form_data)
|
||||
async changeAvatar(selectedFile)
|
||||
{
|
||||
let response = await this.client._patch_file(`/api/profiles/settings`, form_data);
|
||||
let response_data = await response.json();
|
||||
const formData = new FormData();
|
||||
formData.append('avatar', selectedFile);
|
||||
|
||||
return response_data;
|
||||
const response = await this.client._patch_file(`/api/profiles/settings`, formData);
|
||||
const responseData = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
console.log('save', responseData);
|
||||
this.avatar_url = responseData.avatar.substr(responseData.avatar.indexOf('static') - 1);
|
||||
return null;
|
||||
}
|
||||
return responseData;
|
||||
}
|
||||
|
||||
async deleteAvatar() {
|
||||
const response = await this.client._delete('/api/profiles/settings');
|
||||
const responseData = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
console.log('delete', responseData);
|
||||
this.avatar_url = responseData.avatar.substr(responseData.avatar.indexOf('static') - 1);
|
||||
return null;
|
||||
}
|
||||
return responseData;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Tourmanent
|
||||
*/
|
||||
async init()
|
||||
{
|
||||
let response = await this.client._get(`/api/tournaments/${id}`);
|
||||
let response = await this.client._get(`/api/tournaments/${this.id}`);
|
||||
|
||||
if (response.status !== 200)
|
||||
return response.status;
|
||||
|
@ -17,12 +17,12 @@ class Tourmanents
|
||||
/**
|
||||
*
|
||||
* @param {Number} id
|
||||
* @returns {?Promise<Tournament>}
|
||||
* @returns {Promise<Tournament>}
|
||||
*/
|
||||
async getTournament(id)
|
||||
{
|
||||
let tournament = new Tourmanent(this.client);
|
||||
if (await tournament.init(id))
|
||||
let tournament = new Tourmanent(this.client, id);
|
||||
if (await tournament.init())
|
||||
return null;
|
||||
return tournament;
|
||||
}
|
||||
@ -32,17 +32,13 @@ class Tourmanents
|
||||
* @param {Number} nb_players
|
||||
* @param {Number} nb_players_by_game
|
||||
* @param {String} name
|
||||
* @returns
|
||||
* @returns {Response}
|
||||
*/
|
||||
async createTournament(nb_players, nb_players_by_game, name = "")
|
||||
{
|
||||
let response = await this.client._post("/api/tournaments/", {nb_players: nb_players, nb_players_by_game: nb_players_by_game, name: name});
|
||||
|
||||
if (response.status !== 200)
|
||||
return response.status;
|
||||
|
||||
let response_data = await response.json();
|
||||
return response_data;
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +67,8 @@ class Tourmanents
|
||||
tournament_data.started,
|
||||
tournament_data.finished,
|
||||
tournament_data.levels,
|
||||
tournament_data.id));
|
||||
tournament_data.id,
|
||||
tournament_data.state));
|
||||
});
|
||||
|
||||
return tournaments;
|
||||
|
Reference in New Issue
Block a user