add: register page
This commit is contained in:
15
frontend/static/js/api/accounts.js
Normal file
15
frontend/static/js/api/accounts.js
Normal 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 }
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user