feat(inscription): email accusé réception, photos enfants, formulaires identité
- Backend: mail après inscription parent avec n° dossier, UPLOAD_PHOTOS_DIR, réponse API - Frontend: imageBytes + payload photo, utils email/code postal/téléphone, champs dédiés - Formulaires admin, login (focus), personal_info, child_card, custom_app_text_field Made-with: Cursor
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../models/user_registration_data.dart';
|
||||
import 'email_utils.dart';
|
||||
|
||||
/// Construction du body `POST /auth/register/parent` à partir du state d'inscription.
|
||||
/// Aligné sur [RegisterParentCompletDto] (backend).
|
||||
@@ -14,9 +16,13 @@ class ParentRegistrationPayload {
|
||||
/// Retourne un message d'erreur utilisateur, ou `null` si le formulaire est cohérent.
|
||||
static String? validateForApi(UserRegistrationData d) {
|
||||
final p1 = d.parent1;
|
||||
if (p1.email.trim().isEmpty) {
|
||||
final p1Email = normalizeEmailText(p1.email);
|
||||
if (p1Email.isEmpty) {
|
||||
return 'L’email du parent principal est requis.';
|
||||
}
|
||||
if (!isValidEmailFormat(p1Email)) {
|
||||
return 'L’email du parent principal n’est pas au bon format.';
|
||||
}
|
||||
if (p1.firstName.trim().length < 2) {
|
||||
return 'Le prénom du parent principal doit contenir au moins 2 caractères.';
|
||||
}
|
||||
@@ -41,12 +47,16 @@ class ParentRegistrationPayload {
|
||||
p2.lastName.trim().isNotEmpty ||
|
||||
p2.phone.trim().isNotEmpty;
|
||||
if (any) {
|
||||
if (p2.email.trim().isEmpty ||
|
||||
final p2Email = normalizeEmailText(p2.email);
|
||||
if (p2Email.isEmpty ||
|
||||
p2.firstName.trim().length < 2 ||
|
||||
p2.lastName.trim().length < 2) {
|
||||
return 'Les informations du co-parent sont incomplètes (email, prénom et nom requis).';
|
||||
}
|
||||
if (p2.email.trim().toLowerCase() == p1.email.trim().toLowerCase()) {
|
||||
if (!isValidEmailFormat(p2Email)) {
|
||||
return 'L’email du co-parent n’est pas au bon format.';
|
||||
}
|
||||
if (p2Email == p1Email) {
|
||||
return 'L’email du co-parent doit être différent de celui du parent principal.';
|
||||
}
|
||||
final tel2 = _normalizePhone(p2.phone);
|
||||
@@ -114,7 +124,7 @@ class ParentRegistrationPayload {
|
||||
p2.postalCode.trim() == p1.postalCode.trim() &&
|
||||
p2.city.trim() == p1.city.trim();
|
||||
|
||||
body['co_parent_email'] = p2.email.trim();
|
||||
body['co_parent_email'] = normalizeEmailText(p2.email);
|
||||
body['co_parent_prenom'] = p2.firstName.trim();
|
||||
body['co_parent_nom'] = p2.lastName.trim();
|
||||
body['co_parent_meme_adresse'] = sameAddr;
|
||||
@@ -142,7 +152,7 @@ class ParentRegistrationPayload {
|
||||
static Map<String, dynamic> _childToJson(ChildData c, int index, String parentNom) {
|
||||
final map = <String, dynamic>{
|
||||
'genre': apiGenres.contains(c.genre) ? c.genre : 'Autre',
|
||||
'grossesse_multiple': false,
|
||||
'grossesse_multiple': c.multipleBirth,
|
||||
};
|
||||
|
||||
final prenom = c.firstName.trim();
|
||||
@@ -180,20 +190,40 @@ class ParentRegistrationPayload {
|
||||
|
||||
/// (`dataUrl`, `filename`) ou `null` si pas de fichier lisible.
|
||||
static (String, String)? _childPhotoBase64(ChildData c, int index, String prenom) {
|
||||
final file = c.imageFile;
|
||||
if (file == null) return null;
|
||||
try {
|
||||
if (!file.existsSync()) return null;
|
||||
final bytes = file.readAsBytesSync();
|
||||
if (bytes.isEmpty) return null;
|
||||
final b64 = base64Encode(bytes);
|
||||
final safeName = prenom.isNotEmpty
|
||||
? '${prenom.toLowerCase().replaceAll(RegExp(r'[^a-z0-9]+'), '_')}.jpg'
|
||||
: 'enfant_${index + 1}.jpg';
|
||||
return ('data:image/jpeg;base64,$b64', safeName);
|
||||
} catch (_) {
|
||||
return null;
|
||||
Uint8List? bytes = c.imageBytes;
|
||||
if (bytes == null || bytes.isEmpty) {
|
||||
final file = c.imageFile;
|
||||
if (file == null) return null;
|
||||
try {
|
||||
if (!file.existsSync()) return null;
|
||||
bytes = file.readAsBytesSync();
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (bytes.isEmpty) return null;
|
||||
final b64 = base64Encode(bytes);
|
||||
var mime = 'jpeg';
|
||||
if (bytes.length >= 8) {
|
||||
if (bytes[0] == 0x89 &&
|
||||
bytes[1] == 0x50 &&
|
||||
bytes[2] == 0x4E &&
|
||||
bytes[3] == 0x47) {
|
||||
mime = 'png';
|
||||
} else if (bytes[0] == 0xFF && bytes[1] == 0xD8) {
|
||||
mime = 'jpeg';
|
||||
} else if (bytes.length >= 12 &&
|
||||
bytes[0] == 0x52 &&
|
||||
bytes[1] == 0x49 &&
|
||||
bytes[2] == 0x46 &&
|
||||
bytes[3] == 0x46) {
|
||||
mime = 'webp';
|
||||
}
|
||||
}
|
||||
final safeName = prenom.isNotEmpty
|
||||
? '${prenom.toLowerCase().replaceAll(RegExp(r'[^a-z0-9]+'), '_')}.$mime'
|
||||
: 'enfant_${index + 1}.$mime';
|
||||
return ('data:image/$mime;base64,$b64', safeName);
|
||||
}
|
||||
|
||||
static void _putIfNonEmpty(Map<String, dynamic> m, String key, String value) {
|
||||
|
||||
Reference in New Issue
Block a user