feat: Gestion des secteurs et migration v3.0.4+304
- Ajout système complet de gestion des secteurs avec contours géographiques - Import des contours départementaux depuis GeoJSON - API REST pour la gestion des secteurs (/api/sectors) - Service de géolocalisation pour déterminer les secteurs - Migration base de données avec tables x_departements_contours et sectors_adresses - Interface Flutter pour visualisation et gestion des secteurs - Ajout thème sombre dans l'application - Corrections diverses et optimisations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
287
app/lib/presentation/auth/register_page.dart
Normal file → Executable file
287
app/lib/presentation/auth/register_page.dart
Normal file → Executable file
@@ -6,10 +6,8 @@ import 'dart:math' as math;
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:geosector_app/core/repositories/user_repository.dart';
|
||||
import 'package:geosector_app/presentation/widgets/custom_button.dart';
|
||||
import 'package:geosector_app/presentation/widgets/custom_text_field.dart';
|
||||
import 'package:geosector_app/core/services/connectivity_service.dart';
|
||||
import 'package:geosector_app/presentation/widgets/connectivity_indicator.dart';
|
||||
import 'package:geosector_app/core/services/app_info_service.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@@ -73,8 +71,10 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
final String _hiddenToken = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
// Valeurs pour le captcha simple
|
||||
final int _captchaNum1 = 2 + (DateTime.now().second % 5); // Nombre entre 2 et 6
|
||||
final int _captchaNum2 = 3 + (DateTime.now().minute % 4); // Nombre entre 3 et 6
|
||||
final int _captchaNum1 =
|
||||
2 + (DateTime.now().second % 5); // Nombre entre 2 et 6
|
||||
final int _captchaNum2 =
|
||||
3 + (DateTime.now().minute % 4); // Nombre entre 3 et 6
|
||||
|
||||
// État de la connexion Internet et de la plateforme
|
||||
bool _isConnected = false;
|
||||
@@ -100,7 +100,9 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
// Fallback sur la version du AppInfoService si elle existe
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_appVersion = AppInfoService.fullVersion.split(' ').last; // Extraire juste le numéro
|
||||
_appVersion = AppInfoService.fullVersion
|
||||
.split(' ')
|
||||
.last; // Extraire juste le numéro
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -164,7 +166,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
|
||||
try {
|
||||
// Utiliser l'API interne de geosector pour récupérer les villes par code postal
|
||||
final baseUrl = Uri.base.origin; // Récupère l'URL de base (ex: https://app.geosector.fr)
|
||||
final baseUrl = Uri
|
||||
.base.origin; // Récupère l'URL de base (ex: https://app.geosector.fr)
|
||||
final apiUrl = '$baseUrl/api/villes?code_postal=$postalCode';
|
||||
|
||||
final response = await http.get(
|
||||
@@ -246,7 +249,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
child: CustomPaint(
|
||||
painter: DotsPainter(),
|
||||
child: const SizedBox(width: double.infinity, height: double.infinity),
|
||||
child: const SizedBox(
|
||||
width: double.infinity, height: double.infinity),
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
@@ -289,7 +293,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
if (mounted && _isConnected != isConnected) {
|
||||
setState(() {
|
||||
_isConnected = isConnected;
|
||||
_connectionType = connectivityService.connectionType;
|
||||
_connectionType =
|
||||
connectivityService.connectionType;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -336,7 +341,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
if (_isConnected && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Connexion Internet $_connectionType détectée.'),
|
||||
content: Text(
|
||||
'Connexion Internet $_connectionType détectée.'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
@@ -388,7 +394,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer votre email';
|
||||
}
|
||||
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
|
||||
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$')
|
||||
.hasMatch(value)) {
|
||||
return 'Veuillez entrer un email valide';
|
||||
}
|
||||
return null;
|
||||
@@ -415,7 +422,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
CustomTextField(
|
||||
controller: _postalCodeController,
|
||||
label: 'Code postal de l\'amicale',
|
||||
hintText: 'Entrez le code postal de votre amicale',
|
||||
hintText:
|
||||
'Entrez le code postal de votre amicale',
|
||||
prefixIcon: Icons.location_on_outlined,
|
||||
keyboardType: TextInputType.number,
|
||||
isRequired: true,
|
||||
@@ -443,7 +451,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
children: [
|
||||
Text(
|
||||
'Commune de l\'amicale',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
style:
|
||||
theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
@@ -473,7 +482,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
child: _isLoadingCities
|
||||
? const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
@@ -485,16 +495,20 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
Icons.location_city_outlined,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
hintText: _postalCodeController.text.length < 3
|
||||
hintText: _postalCodeController
|
||||
.text.length <
|
||||
3
|
||||
? 'Entrez d\'abord au moins 3 chiffres du code postal'
|
||||
: _cities.isEmpty
|
||||
? 'Aucune commune trouvée pour ce code postal'
|
||||
: 'Sélectionnez une commune',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderRadius:
|
||||
BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
@@ -512,13 +526,18 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
// Mettre à jour le code postal avec celui de la ville sélectionnée
|
||||
if (newValue != null) {
|
||||
// Désactiver temporairement le listener pour éviter une boucle infinie
|
||||
_postalCodeController.removeListener(_onPostalCodeChanged);
|
||||
_postalCodeController
|
||||
.removeListener(
|
||||
_onPostalCodeChanged);
|
||||
|
||||
// Mettre à jour le code postal
|
||||
_postalCodeController.text = newValue.postalCode;
|
||||
_postalCodeController.text =
|
||||
newValue.postalCode;
|
||||
|
||||
// Réactiver le listener
|
||||
_postalCodeController.addListener(_onPostalCodeChanged);
|
||||
_postalCodeController
|
||||
.addListener(
|
||||
_onPostalCodeChanged);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -553,7 +572,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
const SizedBox(height: 8),
|
||||
CustomTextField(
|
||||
controller: _captchaController,
|
||||
label: 'Combien font $_captchaNum1 + $_captchaNum2 ?',
|
||||
label:
|
||||
'Combien font $_captchaNum1 + $_captchaNum2 ?',
|
||||
hintText: 'Entrez le résultat',
|
||||
prefixIcon: Icons.security,
|
||||
keyboardType: TextInputType.number,
|
||||
@@ -590,30 +610,43 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
|
||||
// Bouton d'inscription
|
||||
CustomButton(
|
||||
onPressed: (_isLoading || (_isMobile && !_isConnected))
|
||||
onPressed: (_isLoading ||
|
||||
(_isMobile && !_isConnected))
|
||||
? null
|
||||
: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Vérifier la connexion Internet avant de soumettre
|
||||
// Utiliser l'instance globale de connectivityService définie dans app.dart
|
||||
await connectivityService.checkConnectivity();
|
||||
await connectivityService
|
||||
.checkConnectivity();
|
||||
|
||||
if (!connectivityService.isConnected) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('Aucune connexion Internet. L\'inscription nécessite une connexion active.'),
|
||||
backgroundColor: theme.colorScheme.error,
|
||||
duration: const Duration(seconds: 3),
|
||||
content: const Text(
|
||||
'Aucune connexion Internet. L\'inscription nécessite une connexion active.'),
|
||||
backgroundColor:
|
||||
theme.colorScheme.error,
|
||||
duration:
|
||||
const Duration(seconds: 3),
|
||||
action: SnackBarAction(
|
||||
label: 'Réessayer',
|
||||
onPressed: () async {
|
||||
await connectivityService.checkConnectivity();
|
||||
if (connectivityService.isConnected && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
await connectivityService
|
||||
.checkConnectivity();
|
||||
if (connectivityService
|
||||
.isConnected &&
|
||||
mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Connexion Internet ${connectivityService.connectionType} détectée.'),
|
||||
backgroundColor: Colors.green,
|
||||
content: Text(
|
||||
'Connexion Internet ${connectivityService.connectionType} détectée.'),
|
||||
backgroundColor:
|
||||
Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -625,11 +658,15 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
return;
|
||||
}
|
||||
// Vérifier que le captcha est correct
|
||||
final int? captchaAnswer = int.tryParse(_captchaController.text);
|
||||
if (captchaAnswer != _captchaNum1 + _captchaNum2) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
final int? captchaAnswer = int.tryParse(
|
||||
_captchaController.text);
|
||||
if (captchaAnswer !=
|
||||
_captchaNum1 + _captchaNum2) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('La vérification de sécurité a échoué. Veuillez réessayer.'),
|
||||
content: Text(
|
||||
'La vérification de sécurité a échoué. Veuillez réessayer.'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
@@ -640,11 +677,16 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
final Map<String, dynamic> formData = {
|
||||
'email': _emailController.text.trim(),
|
||||
'name': _nameController.text.trim(),
|
||||
'amicale_name': _amicaleNameController.text.trim(),
|
||||
'postal_code': _postalCodeController.text,
|
||||
'city_name': _selectedCity?.name ?? '',
|
||||
'amicale_name': _amicaleNameController
|
||||
.text
|
||||
.trim(),
|
||||
'postal_code':
|
||||
_postalCodeController.text,
|
||||
'city_name':
|
||||
_selectedCity?.name ?? '',
|
||||
'captcha_answer': captchaAnswer,
|
||||
'captcha_expected': _captchaNum1 + _captchaNum2,
|
||||
'captcha_expected':
|
||||
_captchaNum1 + _captchaNum2,
|
||||
'token': _hiddenToken,
|
||||
};
|
||||
|
||||
@@ -656,12 +698,14 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
try {
|
||||
// Envoyer les données à l'API
|
||||
final baseUrl = Uri.base.origin;
|
||||
final apiUrl = '$baseUrl/api/register';
|
||||
final apiUrl =
|
||||
'$baseUrl/api/register';
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Type':
|
||||
'application/json',
|
||||
},
|
||||
body: json.encode(formData),
|
||||
);
|
||||
@@ -672,23 +716,34 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
});
|
||||
|
||||
// Traiter la réponse
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
final responseData = json.decode(response.body);
|
||||
if (response.statusCode == 200 ||
|
||||
response.statusCode == 201) {
|
||||
final responseData =
|
||||
json.decode(response.body);
|
||||
|
||||
// Vérifier si la réponse indique un succès
|
||||
final bool isSuccess = responseData['success'] == true || responseData['status'] == 'success';
|
||||
final bool isSuccess =
|
||||
responseData['success'] ==
|
||||
true ||
|
||||
responseData['status'] ==
|
||||
'success';
|
||||
|
||||
// Récupérer le message de la réponse
|
||||
final String message = responseData['message'] ??
|
||||
(isSuccess ? 'Inscription réussie !' : 'Échec de l\'inscription. Veuillez réessayer.');
|
||||
final String message = responseData[
|
||||
'message'] ??
|
||||
(isSuccess
|
||||
? 'Inscription réussie !'
|
||||
: 'Échec de l\'inscription. Veuillez réessayer.');
|
||||
|
||||
if (isSuccess) {
|
||||
if (mounted) {
|
||||
// Afficher une boîte de dialogue de succès
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false, // L'utilisateur doit cliquer sur OK
|
||||
builder: (BuildContext context) {
|
||||
barrierDismissible:
|
||||
false, // L'utilisateur doit cliquer sur OK
|
||||
builder:
|
||||
(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
@@ -697,50 +752,88 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
color: Colors.green,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text('Inscription réussie'),
|
||||
Text(
|
||||
'Inscription réussie'),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize:
|
||||
MainAxisSize.min,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
children: [
|
||||
Text(
|
||||
'Votre demande d\'inscription a été enregistrée avec succès.',
|
||||
style: theme.textTheme.bodyLarge,
|
||||
style: theme
|
||||
.textTheme
|
||||
.bodyLarge,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(
|
||||
height: 16),
|
||||
Text(
|
||||
'Vous allez recevoir un email contenant :',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
style: theme
|
||||
.textTheme
|
||||
.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const SizedBox(
|
||||
height: 8),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
children: [
|
||||
Icon(Icons.arrow_right, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons
|
||||
.arrow_right,
|
||||
size: 20,
|
||||
color: theme
|
||||
.colorScheme
|
||||
.primary),
|
||||
const SizedBox(
|
||||
width: 4),
|
||||
const Expanded(
|
||||
child: Text('Votre identifiant de connexion'),
|
||||
child: Text(
|
||||
'Votre identifiant de connexion'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const SizedBox(
|
||||
height: 4),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
children: [
|
||||
Icon(Icons.arrow_right, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons
|
||||
.arrow_right,
|
||||
size: 20,
|
||||
color: theme
|
||||
.colorScheme
|
||||
.primary),
|
||||
const SizedBox(
|
||||
width: 4),
|
||||
const Expanded(
|
||||
child: Text('Un lien pour définir votre mot de passe'),
|
||||
child: Text(
|
||||
'Un lien pour définir votre mot de passe'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(
|
||||
height: 16),
|
||||
Text(
|
||||
'Vérifiez votre boîte de réception et vos spams.',
|
||||
style: TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
fontStyle:
|
||||
FontStyle
|
||||
.italic,
|
||||
color: theme
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(
|
||||
0.7),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -748,15 +841,27 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
// Rediriger vers la page de connexion
|
||||
context.go('/login');
|
||||
Navigator.of(
|
||||
context)
|
||||
.pop();
|
||||
// Rediriger vers splash avec redirection automatique vers login admin
|
||||
context
|
||||
.go('/?action=login&type=admin');
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: theme.colorScheme.primary,
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
style: TextButton
|
||||
.styleFrom(
|
||||
foregroundColor:
|
||||
theme
|
||||
.colorScheme
|
||||
.primary,
|
||||
textStyle:
|
||||
const TextStyle(
|
||||
fontWeight:
|
||||
FontWeight
|
||||
.bold),
|
||||
),
|
||||
child: const Text('OK'),
|
||||
child:
|
||||
const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -769,16 +874,21 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
// Afficher un message d'erreur plus visible
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
builder:
|
||||
(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Erreur d\'inscription'),
|
||||
title: const Text(
|
||||
'Erreur d\'inscription'),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(
|
||||
context)
|
||||
.pop();
|
||||
},
|
||||
child: const Text('OK'),
|
||||
child:
|
||||
const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -786,7 +896,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
);
|
||||
|
||||
// Afficher également un SnackBar
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: Colors.red,
|
||||
@@ -797,9 +908,11 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
} else {
|
||||
// Gérer les erreurs HTTP
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur ${response.statusCode}: ${response.reasonPhrase ?? "Échec de l'inscription"}'),
|
||||
content: Text(
|
||||
'Erreur ${response.statusCode}: ${response.reasonPhrase ?? "Échec de l'inscription"}'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
@@ -813,9 +926,11 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
|
||||
// Gérer les exceptions
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: ${e.toString()}'),
|
||||
content: Text(
|
||||
'Erreur: ${e.toString()}'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
@@ -823,7 +938,9 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
}
|
||||
}
|
||||
},
|
||||
text: (_isMobile && !_isConnected) ? 'Connexion Internet requise' : 'Enregistrer mon amicale',
|
||||
text: (_isMobile && !_isConnected)
|
||||
? 'Connexion Internet requise'
|
||||
: 'Enregistrer mon amicale',
|
||||
isLoading: _isLoading,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
@@ -838,7 +955,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.go('/login');
|
||||
context.go('/?action=login&type=admin');
|
||||
},
|
||||
child: Text(
|
||||
'Se connecter',
|
||||
|
||||
Reference in New Issue
Block a user