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

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-11-29 10:05:49 -05:00
import { client, navigateTo } from "../../index.js";
2023-12-04 06:32:15 -05:00
import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js";
2023-11-27 09:32:17 -05:00
async function register()
{
let username = document.getElementById("username").value;
let password = document.getElementById("password").value;
2023-11-30 19:29:56 -05:00
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");
2023-11-27 09:32:17 -05:00
}
2023-12-04 06:32:15 -05:00
export default class extends AbstractNonAuthentifiedView {
2023-11-27 09:32:17 -05:00
constructor(params) {
2023-11-30 07:05:46 -05:00
super(params, "Register", "/home");
2023-11-27 13:11:15 -05:00
}
async postInit()
{
document.getElementById("register-button").onclick = register;
}
async getHtml() {
2023-11-27 09:32:17 -05:00
return `
<div class=form>
<label>Register</label>
2023-12-16 04:39:07 -05:00
<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>
2023-11-27 09:32:17 -05:00
<a href="/login" class="nav__link" data-link>Login</a>
</div>
`;
}
2023-11-30 10:36:21 -05:00
}