2023-11-27 09:32:17 -05:00
|
|
|
import AbstractView from "../AbstractView.js";
|
2023-11-29 10:05:49 -05:00
|
|
|
import { client, navigateTo } from "../../index.js";
|
2023-11-27 09:32:17 -05:00
|
|
|
|
|
|
|
async function register()
|
|
|
|
{
|
|
|
|
let username = document.getElementById("username").value;
|
|
|
|
let password = document.getElementById("password").value;
|
|
|
|
|
|
|
|
let response = await client.accounts.create(username, password);
|
|
|
|
let response_data = await response.json();
|
|
|
|
|
|
|
|
["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 AbstractView {
|
|
|
|
constructor(params) {
|
|
|
|
super(params);
|
|
|
|
this.setTitle("register");
|
2023-11-27 13:11:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async postInit()
|
|
|
|
{
|
2023-11-29 10:05:49 -05:00
|
|
|
if (client.isAuthentificate())
|
|
|
|
{
|
|
|
|
navigateTo("/home")
|
|
|
|
return;
|
|
|
|
}
|
2023-11-27 13:11:15 -05:00
|
|
|
document.getElementById("button").onclick = register;
|
2023-11-27 09:32:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async getHtml() {
|
|
|
|
return `
|
|
|
|
<div class=form>
|
|
|
|
<label>Register</label>
|
|
|
|
<link rel="stylesheet" href="static/css/accounts/register.css">
|
|
|
|
<input type="text" id="username" placeholder="username">
|
|
|
|
<span id="error_username"></span>
|
|
|
|
<input type="password" id="password" placeholder="password">
|
|
|
|
<span id="error_password"></span>
|
2023-11-27 13:11:15 -05:00
|
|
|
<input type="button" value="register" id="button">
|
2023-11-27 09:32:17 -05:00
|
|
|
<span id="error_user"></span>
|
|
|
|
<a href="/login" class="nav__link" data-link>Login</a>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|