$(document).ready(() => {
    $("#registerForm").submit(() => {
        if ($("#password").val() != $("#passwordConfirm").val()) {
            alert("Password dont match!")
            return;
        }

        $.ajax({
            type: "POST",
            url: "/api/register",
            data: JSON.stringify({
                username: $("#username").val(),
                password: $("#password").val(),
                inviteToken: $("#inviteToken").val()
            }),
            contentType: 'application/json',
            success: () => {
                window.location.href = "/index";
            },
            error: (xhr) => {
                alert (xhr.responseText);
            }
        })
    })
});