blink/frontend/vanilla/html/register.html

284 lines
14 KiB
HTML
Raw Normal View History

2024-03-25 10:07:54 +01:00
<html>
2023-10-18 13:03:41 +02:00
2024-03-04 16:49:36 +01:00
<head>
2024-03-25 10:07:54 +01:00
<title>Blink - Sign Up</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous">
</script>
2024-03-04 16:49:36 +01:00
</head>
2023-10-18 13:03:41 +02:00
2024-03-04 16:49:36 +01:00
<body>
2024-03-25 10:07:54 +01:00
<div class="alert alert-success" role="alert" id="successAlert" style="display: none;">
</div>
<div class="alert alert-danger" role="alert" id="errorAlert" style="display: none;">
2024-03-04 16:49:36 +01:00
</div>
2024-03-25 10:07:54 +01:00
<div class="bg-light py-3 py-md-5">
<div class="container">
<div class="row justify-content-md-center">
<div class="col-12 col-md-11 col-lg-8 col-xl-7 col-xxl-6">
<div class="bg-white p-4 p-md-5 rounded shadow-sm">
<div class="row">
<div class="col-12">
<div class="text-center mb-5">
<!-- <a href="#!">
<img src="./assets/img/bsb-logo.svg" alt="BootstrapBrain Logo" width="175"
height="57">
</a> -->
<h1 style="font-family: sans-serif">Sign up to Blink</h1>
</div>
</div>
</div>
<div class="row gy-3 gy-md-4 overflow-hidden">
<div class="col-12">
<label for="firstName" class="form-label">Name <span
class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
fill="currentColor" class="bi bi-person-vcard" viewBox="0 0 16 16">
<path
d="M5 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m4-2.5a.5.5 0 0 1 .5-.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 1-.5-.5M9 8a.5.5 0 0 1 .5-.5h4a.5.5 0 0 1 0 1h-4A.5.5 0 0 1 9 8m1 2.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5" />
<path
d="M2 2a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2zM1 4a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H8.96c.026-.163.04-.33.04-.5C9 10.567 7.21 9 5 9c-2.086 0-3.8 1.398-3.984 3.181A1.006 1.006 0 0 1 1 12z" />
</svg>
</span>
<input type="text" class="form-control" name="displayname" id="displayname" required
onblur="displaynameFieldLosesFocus();">
<div class="invalid-feedback">
Please fill out this field
</div>
</div>
</div>
<div class="col-12">
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
fill="currentColor" class="bi bi-envelope" viewBox="0 0 16 16">
<path
d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V4Zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1H2Zm13 2.383-4.708 2.825L15 11.105V5.383Zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741ZM1 11.105l4.708-2.897L1 5.383v5.722Z" />
</svg>
</span>
<input type="email" class="form-control" name="email" id="email" required
onblur="emailFieldLosesFocus();">
<div class="invalid-feedback">
2024-03-25 12:12:39 +01:00
Please fill out this field
2024-03-25 10:07:54 +01:00
</div>
</div>
</div>
<div class="col-12">
<label for="password" class="form-label">Password <span
class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
fill="currentColor" class="bi bi-key" viewBox="0 0 16 16">
<path
d="M0 8a4 4 0 0 1 7.465-2H14a.5.5 0 0 1 .354.146l1.5 1.5a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0L13 9.207l-.646.647a.5.5 0 0 1-.708 0L11 9.207l-.646.647a.5.5 0 0 1-.708 0L9 9.207l-.646.647A.5.5 0 0 1 8 10h-.535A4 4 0 0 1 0 8zm4-3a3 3 0 1 0 2.712 4.285A.5.5 0 0 1 7.163 9h.63l.853-.854a.5.5 0 0 1 .708 0l.646.647.646-.647a.5.5 0 0 1 .708 0l.646.647.646-.647a.5.5 0 0 1 .708 0l.646.647.793-.793-1-1h-6.63a.5.5 0 0 1-.451-.285A3 3 0 0 0 4 5z" />
<path d="M4 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0z" />
</svg>
</span>
<input type="password" class="form-control" name="password" id="password" value=""
required onblur="passwordFieldLosesFocus();">
<div class="invalid-feedback" id="passwordErrorLabel">
</div>
</div>
</div>
<div class="col-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="iAgree" id="iAgree"
required>
<label class="form-check-label text-secondary" for="iAgree">
I agree to the <a href="./privacypolicy_and_tou/Terms-Of-Use.html"
class="link-primary text-decoration-none">terms
and conditions</a> and to the <a class="link-primary text-decoration-none"
href="./privacypolicy_and_tou/Privacy-Policy-English.html">privacy
policy</a>
</label>
</div>
</div>
<div class="col-12">
<div class="d-grid">
<button class="btn btn-primary btn-lg" type="button" onclick="register();">Sign
Up</button>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<hr class="mt-5 mb-4 border-secondary-subtle">
2024-03-25 12:01:59 +01:00
<p class="m-0 text-secondary text-center">Already have an account? <a href="login.html"
2024-03-25 10:07:54 +01:00
class="link-primary text-decoration-none">Sign in</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../js/constants.js"></script>
<script src="../js/utils.js"></script>
<script>
2024-03-25 12:12:39 +01:00
/*
* Performs an API POST Request to register the user.
*/
2024-03-25 10:07:54 +01:00
async function register() {
const display_name = document.getElementById('displayname').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
if (!validateFields()) {
return;
}
const options = {
method: 'POST',
headers: createHeaders(null),
body: JSON.stringify({
display_name,
email,
password
}),
};
fetch(`${API_URL}/persons`, options)
.then(response => {
response.json().then(data => {
if (response.ok) {
clearInputFields();
2024-03-25 12:12:39 +01:00
if (!data
.enabled
) { // is the user already enabled or do they need email verification?
showSuccessAlert(
"Congratulations! You've successfully registered to Blink. " +
"Please click on the e-mail we sent you to confirm your account"
);
2024-03-25 10:07:54 +01:00
} else {
2024-03-25 12:12:39 +01:00
showSuccessAlert(
"Congratulations! You've successfully registered to Blink. " +
2024-03-25 10:07:54 +01:00
"You can now <a href='login.html'>log in</a>");
}
window.location.href = '/login.html';
} else {
callbackErrors(data.errors, showErrorAlert);
}
});
})
.catch(err => {
alert("An error has occurred :-( please try again later");
console.error(err);
});
return false;
}
/*
* This function gets called when the displayname field loses focus.
* This is
* done to inform the user that they need to enter at least one
* character in said field.
*/
function displaynameFieldLosesFocus() {
const nameField = document.getElementById("displayname");
if (!nameField.value) {
nameField.classList.add("is-invalid");
2024-03-14 15:29:27 +01:00
} else {
2024-03-25 10:07:54 +01:00
nameField.classList.remove("is-invalid");
2024-03-14 15:29:27 +01:00
}
2024-03-25 10:07:54 +01:00
}
/*
* This function gets called when the e-mail field loses focus. This is
* done to inform the user whether the entered e-mail is in a valid format
*/
function emailFieldLosesFocus() {
const emailField = document.getElementById("email");
if (!emailField.value || !validateEmail(emailField.value)) {
emailField.classList.add("is-invalid");
} else {
emailField.classList.remove("is-invalid");
}
}
/*
* This function gets called when the password field loses focus. This is
* done to inform the user that they are required to enter a password
*/
function passwordFieldLosesFocus() {
const passwordField = document.getElementById("password");
if (!passwordField.value) {
passwordField.classList.add("is-invalid");
document.getElementById('passwordErrorLabel').innerHTML = 'Please fill out this field';
} else if (passwordField.value.length < 5) {
passwordField.classList.add("is-invalid");
document.getElementById('passwordErrorLabel').innerHTML = 'Password must be at least 5 characters';
} else {
passwordField.classList.remove("is-invalid");
}
}
/*
* Validate the field before the submit. This helps to prevent useless API
* calls. Retrurns true or false
*/
function validateFields() {
2024-03-25 12:12:39 +01:00
const emailField = document.getElementById("email");
const passwordField = document.getElementById("password");
const displaynameField = document.getElementById("displayname");
const isAgreeCheckBox = document.getElementById('iAgree');
var isFormValid = true;
if (!emailField.value || !validateEmail(emailField.value)) {
emailField.classList.add("is-invalid");
isFormValid = false;
} else {
emailField.classList.remove("is-invalid");
}
if (!passwordField.value) {
passwordField.classList.add("is-invalid");
document.getElementById('passwordErrorLabel').innerHTML = 'Please fill out this field';
isFormValid = false;
} else if (passwordField.value.length < 5) {
passwordField.classList.add("is-invalid");
document.getElementById('passwordErrorLabel').innerHTML = 'Password must be at least 5 characters';
isFormValid = false;
} else {
passwordField.classList.remove("is-invalid");
}
if (!displaynameField.value) {
displaynameField.classList.add("is-invalid");
isFormValid = false;
} else {
displaynameField.classList.remove("is-invalid");
}
if (!isAgreeCheckBox.checked) {
isFormValid = false;
} else {
2024-03-25 10:07:54 +01:00
}
2024-03-25 12:12:39 +01:00
return isFormValid;
2024-03-25 10:07:54 +01:00
}
function showSuccessAlert(message) {
const successAlert = document.getElementById('successAlert');
successAlert.innerHTML = message;
successAlert.style.display = 'block';
}
2024-03-25 12:12:39 +01:00
function showErrorAlert(message) {
2024-03-25 10:07:54 +01:00
const errorAlert = document.getElementById('errorAlert');
errorAlert.innerHTML = message;
errorAlert.style.display = 'block';
}
</script>
2024-03-04 16:49:36 +01:00
</body>
2024-03-25 10:07:54 +01:00
2024-03-04 16:49:36 +01:00
</html>