feat: création branche singletons - début refactorisation
- Sauvegarde des fichiers critiques - Préparation transformation ApiService en singleton - Préparation création CurrentUserService et CurrentAmicaleService - Objectif: renommer Box users -> user
This commit is contained in:
@@ -73,10 +73,8 @@ 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;
|
||||
@@ -102,9 +100,7 @@ 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
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -168,8 +164,7 @@ 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(
|
||||
@@ -251,7 +246,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
child: CustomPaint(
|
||||
painter: DotsPainter(),
|
||||
child: Container(width: double.infinity, height: double.infinity),
|
||||
child: const SizedBox(width: double.infinity, height: double.infinity),
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
@@ -282,8 +277,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
Text(
|
||||
'Enregistrez votre amicale sur GeoSector',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color:
|
||||
theme.colorScheme.onBackground.withOpacity(0.7),
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
@@ -295,8 +289,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
if (mounted && _isConnected != isConnected) {
|
||||
setState(() {
|
||||
_isConnected = isConnected;
|
||||
_connectionType =
|
||||
connectivityService.connectionType;
|
||||
_connectionType = connectivityService.connectionType;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -343,8 +336,7 @@ 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,
|
||||
),
|
||||
);
|
||||
@@ -396,8 +388,7 @@ 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;
|
||||
@@ -424,8 +415,7 @@ 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,
|
||||
@@ -453,13 +443,12 @@ 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.onBackground,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
const Text(
|
||||
' •',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
@@ -484,8 +473,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
child: _isLoadingCities
|
||||
? const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 16),
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
@@ -497,20 +485,16 @@ 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,
|
||||
),
|
||||
@@ -528,18 +512,13 @@ 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);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -574,8 +553,7 @@ 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,
|
||||
@@ -612,43 +590,30 @@ 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -660,15 +625,11 @@ 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,
|
||||
),
|
||||
);
|
||||
@@ -679,16 +640,11 @@ 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,
|
||||
};
|
||||
|
||||
@@ -700,14 +656,12 @@ 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),
|
||||
);
|
||||
@@ -718,34 +672,23 @@ 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: [
|
||||
@@ -754,84 +697,50 @@ 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,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Vous allez recevoir un email contenant :',
|
||||
style: theme
|
||||
.textTheme
|
||||
.bodyMedium,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
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),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Votre identifiant de connexion'),
|
||||
Icon(Icons.arrow_right, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
const Expanded(
|
||||
child: Text('Votre identifiant de connexion'),
|
||||
),
|
||||
],
|
||||
),
|
||||
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),
|
||||
SizedBox(
|
||||
width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Un lien pour définir votre mot de passe'),
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
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),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -839,25 +748,15 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(
|
||||
context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
// Rediriger vers la page de connexion
|
||||
context
|
||||
.go('/login');
|
||||
context.go('/login');
|
||||
},
|
||||
child: Text('OK'),
|
||||
style: TextButton
|
||||
.styleFrom(
|
||||
foregroundColor:
|
||||
theme
|
||||
.colorScheme
|
||||
.primary,
|
||||
textStyle: TextStyle(
|
||||
fontWeight:
|
||||
FontWeight
|
||||
.bold),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: theme.colorScheme.primary,
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -870,21 +769,16 @@ 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'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -892,8 +786,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
);
|
||||
|
||||
// Afficher également un SnackBar
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: Colors.red,
|
||||
@@ -904,11 +797,9 @@ 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,
|
||||
),
|
||||
);
|
||||
@@ -922,11 +813,9 @@ 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,
|
||||
),
|
||||
);
|
||||
@@ -934,9 +823,7 @@ 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),
|
||||
|
||||
Reference in New Issue
Block a user