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

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-11-29 10:05:49 -05:00
import { client, navigateTo } from "../../index.js";
2023-12-17 14:17:52 -05:00
import { clear, fill_errors } from "../../utils/formUtils.js";
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
2023-11-27 09:32:17 -05:00
async function register()
{
2023-12-17 14:17:52 -05:00
let username = document.getElementById("username-input").value;
let password = document.getElementById("password-input").value;
2023-11-27 09:32:17 -05:00
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
}