ft_transcendence/frontend/static/js/views/accounts/RegisterView.js

48 lines
1.3 KiB
JavaScript

import { client, navigateTo } from "../../index.js";
import { clear, fill_errors } from "../../utils/formUtils.js";
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
async function register()
{
let username = document.getElementById("username-input").value;
let password = document.getElementById("password-input").value;
let response_data = await client.account.create(username, password);
if (response_data == null)
{
navigateTo("/home");
return;
}
clear("innerHTML", ["username", "user", "password"]);
fill_errors(response_data, "innerHTML");
}
export default class extends AbstractNonAuthentifiedView {
constructor(params) {
super(params, "Register", "/home");
}
async postInit()
{
document.getElementById("register-button").onclick = register;
}
async getHtml() {
return `
<div class=form>
<label>Register</label>
<link rel="stylesheet" href="/static/css/accounts/register.css">
<input type="text" id="username-input" placeholder="username">
<span id="username"></span>
<input type="password" id="password-input" placeholder="password">
<span id="password"></span>
<input type="button" value="Register" id="register-button">
<span id="user"></span>
<a href="/login" class="nav__link" data-link>Login</a>
</div>
`;
}
}