feat: Integrate Firebase Authentication and Firestore

- Added Firebase configuration to Android and iOS projects.
- Created `google-services.json` and `GoogleService-Info.plist` for Firebase setup.
- Implemented `AuthService` for handling user authentication with Firebase.
- Updated `UserProvider` to manage user data with Firestore.
- Refactored `ProfileContent`, `LoginPage`, and `SignUpPage` to use the new authentication service.
- Removed the old `UserService` and replaced it with Firestore-based user management.
- Added Firebase options in `firebase_options.dart` for platform-specific configurations.
- Updated dependencies in `pubspec.yaml` for Firebase packages.
This commit is contained in:
Dayron
2025-10-06 18:57:30 +02:00
parent 0b9a140620
commit ec0bc59a70
16 changed files with 609 additions and 374 deletions

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:bcrypt/bcrypt.dart';
import 'package:provider/provider.dart';
import '../models/user.dart';
import '../services/user_service.dart';
import '../services/auth_service.dart';
import '../providers/user_provider.dart';
class SignUpPage extends StatefulWidget {
const SignUpPage({super.key});
@@ -17,7 +18,7 @@ class _SignUpPageState extends State<SignUpPage> {
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _confirmPasswordController = TextEditingController();
final _userService = UserService();
final _authService = AuthService();
bool _isLoading = false;
bool _obscurePassword = true;
@@ -84,39 +85,29 @@ class _SignUpPageState extends State<SignUpPage> {
});
try {
// Vérifier si l'email existe déjà
bool emailExists = await _userService.emailExists(
_emailController.text.trim(),
);
if (emailExists) {
_showErrorDialog('Cet email est déjà utilisé');
return;
}
// Hasher le mot de passe
String hashedPassword = BCrypt.hashpw(
_passwordController.text,
BCrypt.gensalt(),
// Créer le compte avec Firebase Auth
final userCredential = await _authService.createAccount(
email: _emailController.text.trim(),
password: _passwordController.text,
);
// Créer l'utilisateur
// Créer l'objet User
User newUser = User(
id: userCredential.user!.uid,
nom: _nomController.text.trim(),
prenom: _prenomController.text.trim(),
email: _emailController.text.trim().toLowerCase(),
password: hashedPassword,
email: _emailController.text.trim(),
);
// Sauvegarder l'utilisateur
bool success = await _userService.addUser(newUser);
// Sauvegarder les données utilisateur dans Firestore
await Provider.of<UserProvider>(context, listen: false).saveUserData(newUser);
if (success) {
_showSuccessDialog();
} else {
_showErrorDialog('Erreur lors de la création du compte');
}
// Mettre à jour le displayName
await _authService.updateDisplayName(displayName: newUser.fullName);
_showSuccessDialog();
} catch (e) {
_showErrorDialog('Une erreur est survenue: ${e.toString()}');
_showErrorDialog('Erreur lors de la création du compte: ${e.toString()}');
} finally {
setState(() {
_isLoading = false;
@@ -351,3 +342,4 @@ class _SignUpPageState extends State<SignUpPage> {
);
}
}