parcel/templates/admin/setup.html

73 lines
2.9 KiB
HTML

{% extends "base.html" %}
{% block title %}Setup{% endblock %}
{% block content %}
<div class="grow container mx-auto flex justify-center items-center mt-4 p-4 md:p-0">
<div class="flex flex-col gap-2 border rounded-md shadow-md border-slate-400 dark:border-gray-700
dark:bg-gray-800 p-6 sm:p-4 w-full md:w-[40rem] lg:w-[48rem] aspect-[16/9]">
<h1 class="text-2xl font-semibold">⚙️ Initial Setup</h1>
<p class="my-4 text-lg">
Welcome to the initial setup of a new 📦 Parcel installation.
</p>
<p class="mb-4">
To set up your installation, you need to create the username and password for the
first administrator user. You can add more administrators or normal users later.
</p>
<div id="error" class="text-danger">
{% if error %}{{ error }}{% endif %}
</div>
<form id="setup-form" action="/admin/setup" method="POST" class="form">
<input type="hidden" name="token" value="{{ token }}" />
<label for="username">Administrator Username</label>
<input class="field" name="username" type="text" placeholder="Administrator Username" />
<label for="password">Administrator Password</label>
<input class="field" name="password" type="password" placeholder="Administrator Password" />
<input class="field" name="confirm" type="password" placeholder="Confirm Administrator Password" />
<div class="buttons end">
<button type="submit" class="button">Create administrator</button>
</div>
</form>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
document.querySelector("form#setup-form").addEventListener("submit", (event) => {
const username = document.querySelector("input[name='username']").value;
const password = document.querySelector("input[name='password']").value;
const confirm = document.querySelector("input[name='confirm']").value;
// Check to make sure that the username is not empty.
if (username.length === 0) {
event.preventDefault();
document.querySelector("#error").innerHTML = "The administrator username cannot be empty.";
return;
}
// Check to make sure that the password is not empty; If it is, then cancel the submission event
if (password.length === 0) {
event.preventDefault();
document.querySelector("#error").innerHTML = "The administrator password cannot be empty.";
return;
}
// Check to make sure that the password and the confirmation are the same; If they are not, then
// cancel the submission event and set the <div id="error"> content to a suitable error message.
if (password !== confirm) {
event.preventDefault();
document.querySelector("#error").innerHTML = "The passwords do not match.";
return;
}
// Disable the submit button so we don't try multiple submissions.
document.querySelector("button[type=submit]").disabled = true;
});
</script>
{% endblock %}