import { client, navigateTo } from "../../index.js"; import AbstractAuthentifiedView from "../AbstractNonAuthentified.js"; async function register() { let username = document.getElementById("username").value; let password = document.getElementById("password").value; let response_data = await client.account.create(username, password); if (response_data == null) { navigateTo("/home"); return; } ["username", "user", "password"].forEach(error_field => { let error_display = document.getElementById(`error_${error_field}`); if (error_display != null) error_display.innerHTML = ""; }); Object.keys(response_data).forEach(error_field => { let error_display = document.getElementById(`error_${error_field}`); if (error_display != null) error_display.innerHTML = response_data[error_field]; }); } export default class extends AbstractAuthentifiedView { constructor(params) { super(params, "Register", "/home"); } async postInit() { document.getElementById("button").onclick = register; } async getHtml() { return `
`; } }