Altersberechung vür Einwilligung
This commit is contained in:
parent
9940d9498b
commit
37a2c9b015
@ -71,11 +71,12 @@ router.post("/create", async (req, res) => {
|
||||
/* =========================
|
||||
Pflicht-Zustimmungen
|
||||
========================= */
|
||||
if (!u.agreeConsent || !u.agreeAgb || !u.agreeSepa) {
|
||||
|
||||
if (!u.agreeAgb || !u.agreeSepa || (age < 18 && !u.agreeConsent)) {
|
||||
return res.render("register", {
|
||||
vertragsarten,
|
||||
selectedVertrag: u.vertragsvariante,
|
||||
error: "Bitte bestätige alle rechtlichen Hinweise, um fortzufahren.",
|
||||
error: "Bitte bestätige alle erforderlichen Hinweise.",
|
||||
formData: u,
|
||||
});
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
<div class="col-md-6">
|
||||
<input type="date"
|
||||
name="geburtsdatum"
|
||||
id="geburtsdatum"
|
||||
class="form-control"
|
||||
required>
|
||||
</div>
|
||||
@ -138,7 +139,7 @@
|
||||
<hr class="my-4">
|
||||
<h5>Rechtliches</h5>
|
||||
|
||||
<div class="form-check mb-2">
|
||||
<div class="form-check mb-2" id="consentBlock" style="display:none;">
|
||||
<input class="form-check-input"
|
||||
type="checkbox"
|
||||
id="agreeConsent"
|
||||
@ -176,4 +177,37 @@
|
||||
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const birthInput = document.getElementById("geburtsdatum");
|
||||
const consentBlock = document.getElementById("consentBlock");
|
||||
const consentCheckbox = document.getElementById("agreeConsent");
|
||||
|
||||
function checkAge() {
|
||||
if (!birthInput.value) return;
|
||||
|
||||
const birthDate = new Date(birthInput.value);
|
||||
const today = new Date();
|
||||
|
||||
let age = today.getFullYear() - birthDate.getFullYear();
|
||||
const monthDiff = today.getMonth() - birthDate.getMonth();
|
||||
|
||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
|
||||
age--;
|
||||
}
|
||||
|
||||
if (age < 18) {
|
||||
consentBlock.style.display = "block";
|
||||
consentCheckbox.required = true;
|
||||
} else {
|
||||
consentBlock.style.display = "none";
|
||||
consentCheckbox.required = false;
|
||||
consentCheckbox.checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
birthInput.addEventListener("change", checkAge);
|
||||
});
|
||||
</script>
|
||||
|
||||
<%- include('partials/footer') %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user