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";
|
2023-12-04 06:32:15 -05:00
|
|
|
import AbstractNonAuthentifiedView from "../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;
|
|
|
|
}
|
|
|
|
|
2023-12-16 11:41:31 -05:00
|
|
|
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()
|
|
|
|
{
|
2023-12-16 11:41:31 -05:00
|
|
|
document.getElementById("register-button").onclick = register;
|
2023-11-29 10:10:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2023-12-16 11:41:31 -05:00
|
|
|
<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
|
|
|
}
|