Altersberechung vür Einwilligung

This commit is contained in:
Cay 2026-02-28 15:46:43 +00:00
parent 9940d9498b
commit 37a2c9b015
2 changed files with 38 additions and 3 deletions

View File

@ -71,11 +71,12 @@ router.post("/create", async (req, res) => {
/* ========================= /* =========================
Pflicht-Zustimmungen Pflicht-Zustimmungen
========================= */ ========================= */
if (!u.agreeConsent || !u.agreeAgb || !u.agreeSepa) {
if (!u.agreeAgb || !u.agreeSepa || (age < 18 && !u.agreeConsent)) {
return res.render("register", { return res.render("register", {
vertragsarten, vertragsarten,
selectedVertrag: u.vertragsvariante, selectedVertrag: u.vertragsvariante,
error: "Bitte bestätige alle rechtlichen Hinweise, um fortzufahren.", error: "Bitte bestätige alle erforderlichen Hinweise.",
formData: u, formData: u,
}); });
} }

View File

@ -26,6 +26,7 @@
<div class="col-md-6"> <div class="col-md-6">
<input type="date" <input type="date"
name="geburtsdatum" name="geburtsdatum"
id="geburtsdatum"
class="form-control" class="form-control"
required> required>
</div> </div>
@ -138,7 +139,7 @@
<hr class="my-4"> <hr class="my-4">
<h5>Rechtliches</h5> <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" <input class="form-check-input"
type="checkbox" type="checkbox"
id="agreeConsent" id="agreeConsent"
@ -176,4 +177,37 @@
</form> </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') %> <%- include('partials/footer') %>