add: register page

This commit is contained in:
2023-11-27 15:32:17 +01:00
parent 6a4e161d71
commit a965adfdce
5 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,15 @@
class Accounts
{
constructor (client)
{
this.client = client;
}
async create(username, password)
{
let response = await this.client._post("/api/accounts/register", {username: username, password: password});
return response
}
}
export { Accounts }

View File

@ -1,8 +1,20 @@
import { Accounts } from "./accounts.js";
function extract_token(response)
{
let cookies = response.headers.get("set-cookie");
if (cookies == null)
return null;
token = cookies.slice(cookies.indexOf("=") + 1, cookies.indexOf(';'))
return token;
}
class Client
{
constructor(url)
{
this._url = url;
this.accounts = new Accounts(this);
this._token = undefined;
}
@ -20,12 +32,16 @@ class Client
},
body: JSON.stringify(data),
});
let token = extract_token(response);
if (token != null)
this.token = token;
return response;
}
async login(username, password)
{
return this._post("/api/accounts/login", {username: username, password: password})
let response = await this._post("/api/accounts/login", {username: username, password: password})
return response
}
}