Squash merge de develop vers master. Livrables principaux (ticket #101 et mise au point associée) : - Branchement du formulaire d'inscription parent sur POST /api/v1/auth/register/parent - Payload DTO (parents, enfants, photos base64, CGU) et services Auth - Parcours gestionnaire : cartes dossiers, wizard validation famille, images authentifiées - Scripts d'inscription test (Martin, Durand/Rousseau, Lecomte) ; .gitignore .cursor/ Inclut également les ajustements develop fusionnés dans ce lot (inscription AM, champs relais, etc.). Closes #101 Made-with: Cursor
58 lines
1.7 KiB
Dart
58 lines
1.7 KiB
Dart
import 'package:flutter/services.dart';
|
||
|
||
/// Longueur maximale d’une adresse e-mail (RFC 5321).
|
||
const int kEmailMaxLength = 254;
|
||
|
||
/// Trim + minuscules (usage à la perte de focus et avant validation côté API).
|
||
String normalizeEmailText(String raw) {
|
||
return raw.trim().toLowerCase();
|
||
}
|
||
|
||
/// Motif volontairement simple pour l’UI (pas une validation RFC complète).
|
||
/// Local + @ + domaine avec au moins un point ; pas d’espaces.
|
||
final RegExp kAppEmailPattern = RegExp(
|
||
r'^[a-zA-Z0-9._%+\-]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,63}$',
|
||
);
|
||
|
||
/// Indique si [trimmed] est un e-mail plausible (insensible à la casse).
|
||
bool isValidEmailFormat(String trimmed) {
|
||
final s = normalizeEmailText(trimmed);
|
||
if (s.isEmpty || s.length > kEmailMaxLength) {
|
||
return false;
|
||
}
|
||
return kAppEmailPattern.hasMatch(s);
|
||
}
|
||
|
||
/// Validation centralisée pour les champs e-mail.
|
||
///
|
||
/// Si [allowEmpty] est `true`, une chaîne vide (après trim) est acceptée.
|
||
String? validateEmail(String? raw, {bool allowEmpty = false}) {
|
||
final s = normalizeEmailText(raw ?? '');
|
||
if (s.isEmpty) {
|
||
return allowEmpty ? null : 'L’adresse e-mail est obligatoire.';
|
||
}
|
||
if (s.length > kEmailMaxLength) {
|
||
return 'L’adresse e-mail est trop longue ($kEmailMaxLength caractères maximum).';
|
||
}
|
||
if (!kAppEmailPattern.hasMatch(s)) {
|
||
return 'Le format de l’adresse e-mail est incorrect.';
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// Limite la longueur saisie dans un champ e-mail ([kEmailMaxLength]).
|
||
class EmailMaxLengthFormatter extends TextInputFormatter {
|
||
const EmailMaxLengthFormatter();
|
||
|
||
@override
|
||
TextEditingValue formatEditUpdate(
|
||
TextEditingValue oldValue,
|
||
TextEditingValue newValue,
|
||
) {
|
||
if (newValue.text.length <= kEmailMaxLength) {
|
||
return newValue;
|
||
}
|
||
return oldValue;
|
||
}
|
||
}
|