feat: E.164 phone validation and storage with libphonenumber

- Add giggsey/libphonenumber-for-php, PhoneNumberNormalizer, ValidPhoneNumber rule

- Store subscribers as E.164; mutator normalizes on save; optional phone required from form block

- Migration to normalize legacy subscriber phones; Mailwizz/search/UI/tests updated

- Add run-deploy-from-local.sh and PREREGISTER_DEFAULT_PHONE_REGION in .env.example

Made-with: Cursor
This commit is contained in:
2026-04-04 14:25:52 +02:00
parent 5a67827c23
commit 17e784fee7
21 changed files with 476 additions and 18 deletions

View File

@@ -390,6 +390,7 @@ document.addEventListener('alpine:init', () => {
phase: config.phase,
startAtMs: config.startAtMs,
phoneEnabled: config.phoneEnabled,
phoneRequired: config.phoneRequired === true,
subscribeUrl: config.subscribeUrl,
csrfToken: config.csrfToken,
genericError: config.genericError,
@@ -499,10 +500,16 @@ document.addEventListener('alpine:init', () => {
ok = false;
}
if (this.phoneEnabled) {
const digits = String(this.phone).replace(/\D/g, '');
if (digits.length > 0 && (digits.length < 8 || digits.length > 15)) {
const trimmed = String(this.phone).trim();
if (this.phoneRequired && trimmed === '') {
this.fieldErrors.phone = [this.invalidPhoneMsg];
ok = false;
} else if (trimmed !== '') {
const digits = trimmed.replace(/\D/g, '');
if (digits.length < 8 || digits.length > 15) {
this.fieldErrors.phone = [this.invalidPhoneMsg];
ok = false;
}
}
}
return ok;

View File

@@ -64,7 +64,7 @@
<td class="px-4 py-3 text-slate-900">{{ $subscriber->last_name }}</td>
<td class="px-4 py-3 text-slate-600">{{ $subscriber->email }}</td>
@if ($page->isPhoneFieldEnabledForSubscribers())
<td class="px-4 py-3 text-slate-600">{{ $subscriber->phone ?? '—' }}</td>
<td class="px-4 py-3 text-slate-600">{{ $subscriber->phoneDisplay() ?? '—' }}</td>
@endif
<td class="whitespace-nowrap px-4 py-3 text-slate-600">{{ $subscriber->created_at->timezone(config('app.timezone'))->format('Y-m-d H:i') }}</td>
<td class="px-4 py-3">

View File

@@ -56,13 +56,14 @@
'phase' => $alpinePhase,
'startAtMs' => $page->start_date->getTimestamp() * 1000,
'phoneEnabled' => $page->isPhoneFieldEnabledForSubscribers(),
'phoneRequired' => $page->isPhoneFieldEnabledForSubscribers() && $page->isPhoneFieldRequiredForSubscribers(),
'subscribeUrl' => route('public.subscribe', ['publicPage' => $page]),
'csrfToken' => csrf_token(),
'genericError' => __('Something went wrong. Please try again.'),
'labelDay' => __('day'),
'labelDays' => __('days'),
'invalidEmailMsg' => __('Please enter a valid email address.'),
'invalidPhoneMsg' => __('Please enter a valid phone number (815 digits).'),
'invalidPhoneMsg' => __('Please enter a valid phone number.'),
'formButtonLabel' => $formButtonLabel,
'formButtonColor' => $formButtonColor,
'formButtonTextColor' => $formButtonTextColor,