chore: checkpoint before block builder refactor

This commit is contained in:
2026-04-03 23:03:09 +02:00
parent 330950cc6e
commit 4f3fefca5c
14 changed files with 315 additions and 99 deletions

View File

@@ -2,6 +2,36 @@ import './bootstrap';
import Alpine from 'alpinejs';
/**
* Client-side email check (aligned loosely with RFC-style rules; server is authoritative).
*/
function isValidEmailFormat(value) {
const email = String(value).trim().toLowerCase();
if (email.length < 5 || email.length > 255) {
return false;
}
if (!email.includes('@')) {
return false;
}
const at = email.lastIndexOf('@');
const local = email.slice(0, at);
const domain = email.slice(at + 1);
if (!local || !domain || local.includes('..') || domain.includes('..')) {
return false;
}
if (domain.startsWith('.') || domain.endsWith('.')) {
return false;
}
if (!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(local)) {
return false;
}
if (!/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/i.test(domain)) {
return false;
}
const tld = domain.split('.').pop();
return Boolean(tld && tld.length >= 2);
}
document.addEventListener('alpine:init', () => {
Alpine.data('publicPreregisterPage', (config) => ({
phase: config.phase,
@@ -12,6 +42,8 @@ document.addEventListener('alpine:init', () => {
genericError: config.genericError,
labelDay: config.labelDay,
labelDays: config.labelDays,
invalidEmailMsg: config.invalidEmailMsg,
invalidPhoneMsg: config.invalidPhoneMsg,
days: 0,
hours: 0,
minutes: 0,
@@ -56,15 +88,36 @@ document.addEventListener('alpine:init', () => {
return String(n).padStart(2, '0');
},
validateEmailAndPhone() {
this.fieldErrors = {};
let ok = true;
if (!isValidEmailFormat(this.email)) {
this.fieldErrors.email = [this.invalidEmailMsg];
ok = false;
}
if (this.phoneEnabled) {
const digits = String(this.phone).replace(/\D/g, '');
if (digits.length > 0 && (digits.length < 8 || digits.length > 15)) {
this.fieldErrors.phone = [this.invalidPhoneMsg];
ok = false;
}
}
return ok;
},
async submitForm() {
this.formError = '';
this.fieldErrors = {};
if (!this.validateEmailAndPhone()) {
return;
}
const form = this.$refs.form;
if (form !== undefined && form !== null && !form.checkValidity()) {
form.reportValidity();
return;
}
this.formError = '';
this.fieldErrors = {};
this.submitting = true;
try {
const body = {
@@ -262,10 +315,6 @@ document.addEventListener('alpine:init', () => {
this.errorMessage = cfg.strings.mapFieldsError;
return;
}
if (this.phoneEnabled && !this.fieldPhone) {
this.errorMessage = cfg.strings.mapPhoneError;
return;
}
if (!this.tagField) {
this.errorMessage = cfg.strings.tagFieldError;
return;