65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
class Account
|
|
{
|
|
constructor (client)
|
|
{
|
|
this.client = client;
|
|
}
|
|
|
|
async create(username, password)
|
|
{
|
|
let response = await this.client._post("/api/accounts/register", {username: username, password: password});
|
|
let response_data = await response.json()
|
|
|
|
if (response_data == "user created")
|
|
{
|
|
this._logged = true;
|
|
return null;
|
|
}
|
|
return response_data
|
|
}
|
|
|
|
async delete(password)
|
|
{
|
|
let response = await this.client._delete("/api/accounts/delete", {password: password});
|
|
let response_data = await response.json();
|
|
|
|
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
|
{
|
|
this.client._logged = false;
|
|
return null;
|
|
}
|
|
console.log(response_data)
|
|
if (response_data == "user deleted")
|
|
this.client._logged = false;
|
|
return response_data;
|
|
}
|
|
|
|
async get()
|
|
{
|
|
let response = await this.client._get("/api/accounts/edit");
|
|
let response_data = await response.json();
|
|
|
|
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
|
{
|
|
this.client._logged = false;
|
|
return null;
|
|
}
|
|
return response_data;
|
|
}
|
|
|
|
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 (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
|
{
|
|
this.client._logged = false;
|
|
return null;
|
|
}
|
|
return response_data;
|
|
}
|
|
}
|
|
|
|
export { Account } |