Enhance Google and Apple sign-up methods to include name and firstname parameters
This commit is contained in:
@@ -171,7 +171,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
// This method can be implemented if needed for Google sign-up specific logic.
|
||||
emit(AuthLoading());
|
||||
try {
|
||||
final user = await _authRepository.signUpWithGoogle(event.phoneNumber);
|
||||
final user = await _authRepository.signUpWithGoogle(
|
||||
event.phoneNumber,
|
||||
event.name,
|
||||
event.firstname,
|
||||
);
|
||||
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
@@ -190,7 +194,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
// This method can be implemented if needed for Apple sign-up specific logic.
|
||||
emit(AuthLoading());
|
||||
try {
|
||||
final user = await _authRepository.signUpWithApple(event.phoneNumber);
|
||||
final user = await _authRepository.signUpWithApple(
|
||||
event.phoneNumber,
|
||||
event.name,
|
||||
event.firstname,
|
||||
);
|
||||
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
|
||||
@@ -81,11 +81,17 @@ class AuthGoogleSignInRequested extends AuthEvent {}
|
||||
class AuthGoogleSignUpRequested extends AuthEvent {
|
||||
/// The user's phone number.
|
||||
final String phoneNumber;
|
||||
final String name;
|
||||
final String firstname;
|
||||
|
||||
/// Creates a new [AuthGoogleSignUpRequested] event.
|
||||
///
|
||||
/// The [phoneNumber] parameter is required.
|
||||
const AuthGoogleSignUpRequested({required this.phoneNumber});
|
||||
const AuthGoogleSignUpRequested({
|
||||
required this.phoneNumber,
|
||||
required this.name,
|
||||
required this.firstname,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [phoneNumber];
|
||||
@@ -99,11 +105,17 @@ class AuthAppleSignInRequested extends AuthEvent {}
|
||||
class AuthAppleSignUpRequested extends AuthEvent {
|
||||
/// The user's phone number.
|
||||
final String phoneNumber;
|
||||
final String name;
|
||||
final String firstname;
|
||||
|
||||
/// Creates a new [AuthAppleSignUpRequested] event.
|
||||
///
|
||||
/// The [phoneNumber] parameter is required.
|
||||
const AuthAppleSignUpRequested({required this.phoneNumber});
|
||||
const AuthAppleSignUpRequested({
|
||||
required this.phoneNumber,
|
||||
required this.name,
|
||||
required this.firstname,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [phoneNumber];
|
||||
|
||||
@@ -6,11 +6,11 @@ class LoadingContent extends StatefulWidget {
|
||||
final VoidCallback? onComplete;
|
||||
|
||||
const LoadingContent({
|
||||
Key? key,
|
||||
super.key,
|
||||
this.onBackgroundTask,
|
||||
this.loadingText = "Chargement en cours...",
|
||||
this.onComplete,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<LoadingContent> createState() => _LoadingContentState();
|
||||
@@ -57,7 +57,6 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
widget.onComplete!();
|
||||
}
|
||||
} catch (e) {
|
||||
// Gérer les erreurs si nécessaire
|
||||
print('Erreur lors de la tâche en arrière-plan: $e');
|
||||
}
|
||||
}
|
||||
@@ -72,8 +71,11 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -96,21 +98,21 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Colors.blue.shade400,
|
||||
Colors.purple.shade400,
|
||||
theme.primaryColor.withValues(alpha: 0.8),
|
||||
theme.primaryColor,
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.blue.withOpacity(0.3),
|
||||
color: theme.primaryColor.withValues(alpha: 0.3),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
child: Icon(
|
||||
Icons.travel_explore,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
@@ -130,10 +132,9 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
opacity: _pulseAnimation.value - 0.3,
|
||||
child: Text(
|
||||
widget.loadingText ?? "Chargement en cours...",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade700,
|
||||
color: isDark ? Colors.white : Colors.black,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
@@ -146,8 +147,10 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: LinearProgressIndicator(
|
||||
backgroundColor: Colors.grey.shade300,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue.shade400),
|
||||
backgroundColor: isDark
|
||||
? Colors.grey[800]
|
||||
: Colors.grey.shade300,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(theme.primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:travel_mate/blocs/auth/auth_bloc.dart';
|
||||
import 'package:travel_mate/blocs/auth/auth_event.dart';
|
||||
|
||||
class SignUpPlatformContent extends StatefulWidget {
|
||||
final String platform; // 'google' ou 'apple'
|
||||
@@ -8,13 +11,13 @@ class SignUpPlatformContent extends StatefulWidget {
|
||||
final String? firstName;
|
||||
|
||||
const SignUpPlatformContent({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.platform,
|
||||
this.email,
|
||||
this.phoneNumber,
|
||||
this.name,
|
||||
this.firstName,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<SignUpPlatformContent> createState() => _SignUpPlatformContentState();
|
||||
@@ -53,15 +56,32 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Traitement de l'inscription
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Profil complété avec succès!')),
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget.platform == 'google') {
|
||||
context.read<AuthBloc>().add(
|
||||
AuthGoogleSignUpRequested(
|
||||
phoneNumber: _phoneController.text.trim(),
|
||||
name: _nameController.text.trim(),
|
||||
firstname: _firstNameController.text.trim(),
|
||||
),
|
||||
);
|
||||
} else if (widget.platform == 'apple') {
|
||||
context.read<AuthBloc>().add(
|
||||
AuthAppleSignUpRequested(
|
||||
phoneNumber: _phoneController.text.trim(),
|
||||
name: _nameController.text.trim(),
|
||||
firstname: _firstNameController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildPlatformIndicator() {
|
||||
Widget _buildPlatformIndicator(ThemeData theme) {
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
Color platformColor = widget.platform == 'google'
|
||||
? Colors.red
|
||||
: Colors.black;
|
||||
@@ -75,7 +95,9 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
decoration: BoxDecoration(
|
||||
color: widget.platform == 'google'
|
||||
? Colors.red.shade50
|
||||
: Colors.black.withValues(alpha: 0.05),
|
||||
: (isDark
|
||||
? Colors.grey[900]
|
||||
: Colors.black.withValues(alpha: 0.05)),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: platformColor, width: 1),
|
||||
),
|
||||
@@ -98,13 +120,16 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
backgroundColor: theme.appBarTheme.backgroundColor,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
icon: Icon(Icons.arrow_back, color: theme.iconTheme.color),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
@@ -117,20 +142,25 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Indicateur de plateforme
|
||||
_buildPlatformIndicator(),
|
||||
_buildPlatformIndicator(theme),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// Titre
|
||||
const Text(
|
||||
Text(
|
||||
'Complétez votre profil',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
Text(
|
||||
'Vérifiez et complétez vos informations',
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
@@ -138,11 +168,15 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
// Champ Nom
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Nom',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.person_outline),
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.person_outline),
|
||||
labelStyle: TextStyle(
|
||||
color: isDark ? Colors.white70 : Colors.black87,
|
||||
),
|
||||
),
|
||||
style: TextStyle(color: isDark ? Colors.white : Colors.black),
|
||||
validator: (value) => _validateField(value, 'Nom'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -150,11 +184,15 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
// Champ Prénom
|
||||
TextFormField(
|
||||
controller: _firstNameController,
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Prénom',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.person_outline),
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.person_outline),
|
||||
labelStyle: TextStyle(
|
||||
color: isDark ? Colors.white70 : Colors.black87,
|
||||
),
|
||||
),
|
||||
style: TextStyle(color: isDark ? Colors.white : Colors.black),
|
||||
validator: (value) => _validateField(value, 'Prénom'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -168,28 +206,43 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
prefixIcon: const Icon(Icons.email_outlined),
|
||||
suffixIcon: Icon(
|
||||
Icons.lock_outline,
|
||||
color: Colors.grey[400],
|
||||
color: isDark ? Colors.grey[600] : Colors.grey[400],
|
||||
),
|
||||
labelStyle: TextStyle(
|
||||
color: isDark ? Colors.white70 : Colors.black87,
|
||||
),
|
||||
),
|
||||
enabled: false,
|
||||
style: TextStyle(color: Colors.grey[600]),
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Email fourni par ${widget.platform == 'google' ? 'Google' : 'Apple'}',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[500] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Champ Téléphone
|
||||
TextFormField(
|
||||
controller: _phoneController,
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Numéro de téléphone',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.phone_outlined),
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.phone_outlined),
|
||||
hintText: '+33 6 12 34 56 78',
|
||||
labelStyle: TextStyle(
|
||||
color: isDark ? Colors.white70 : Colors.black87,
|
||||
),
|
||||
hintStyle: TextStyle(
|
||||
color: isDark ? Colors.grey[600] : Colors.grey[400],
|
||||
),
|
||||
),
|
||||
style: TextStyle(color: isDark ? Colors.white : Colors.black),
|
||||
keyboardType: TextInputType.phone,
|
||||
validator: (value) =>
|
||||
_validateField(value, 'Numéro de téléphone'),
|
||||
@@ -200,16 +253,20 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
ElevatedButton(
|
||||
onPressed: _submitForm,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: isDark ? Colors.white : Colors.black,
|
||||
foregroundColor: isDark ? Colors.black : Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
child: Text(
|
||||
'Confirmer mon inscription',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isDark ? Colors.black : Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -217,9 +274,12 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
||||
// Bouton secondaire
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text(
|
||||
child: Text(
|
||||
'Modifier la méthode de connexion',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:sign_in_button/sign_in_button.dart';
|
||||
import 'package:travel_mate/components/loading/laoding_content.dart';
|
||||
import 'package:travel_mate/components/signup/sign_up_platform_content.dart';
|
||||
import 'package:travel_mate/services/auth_service.dart';
|
||||
import '../blocs/auth/auth_bloc.dart';
|
||||
import '../blocs/auth/auth_event.dart';
|
||||
import '../blocs/auth/auth_state.dart';
|
||||
@@ -28,6 +29,7 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
bool _obscureConfirmPassword = true;
|
||||
|
||||
final _errorService = ErrorService();
|
||||
final _authService = AuthService();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -327,20 +329,38 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LoadingContent(
|
||||
onBackgroundTask: () async {
|
||||
// Effectuer la requête vers Google
|
||||
final platformData = await _fetchGoogleSignInData();
|
||||
return platformData;
|
||||
// Effectuer la requête vers Google et donner les informations de l'utilisateur pour le signup
|
||||
await _authService.signInWithGoogle();
|
||||
},
|
||||
onComplete: () {
|
||||
// Fermer le loading et naviguer vers SignUpPlatformContent
|
||||
Navigator.pop(context); // Fermer LoadingContent
|
||||
Navigator.push(
|
||||
Navigator.pop(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(platform: 'google'),
|
||||
),
|
||||
);
|
||||
); // Fermer LoadingContent
|
||||
final user = _authService.currentUser;
|
||||
if (user != null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(
|
||||
platform: 'google',
|
||||
email: user.email ?? '',
|
||||
firstName:
|
||||
user.displayName
|
||||
?.split(' ')
|
||||
.first ??
|
||||
'Prénom',
|
||||
name:
|
||||
user.displayName
|
||||
?.split(' ')
|
||||
.skip(1)
|
||||
.join(' ') ??
|
||||
'Nom',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -360,19 +380,38 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
builder: (context) => LoadingContent(
|
||||
onBackgroundTask: () async {
|
||||
// Effectuer la requête vers Google
|
||||
final platformData = await
|
||||
return platformData;
|
||||
await _authService.signInWithApple();
|
||||
},
|
||||
onComplete: () {
|
||||
// Fermer le loading et naviguer vers SignUpPlatformContent
|
||||
Navigator.pop(context); // Fermer LoadingContent
|
||||
Navigator.push(
|
||||
Navigator.pop(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(platform: 'apple'),
|
||||
),
|
||||
);
|
||||
); // Fermer LoadingContent
|
||||
|
||||
final user = _authService.currentUser;
|
||||
if (user != null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(
|
||||
platform: 'apple',
|
||||
email: user.email ?? '',
|
||||
firstName:
|
||||
user.displayName
|
||||
?.split(' ')
|
||||
.first ??
|
||||
'Prénom',
|
||||
name:
|
||||
user.displayName
|
||||
?.split(' ')
|
||||
.skip(1)
|
||||
.join(' ') ??
|
||||
'Nom',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -116,7 +116,11 @@ class AuthRepository {
|
||||
///
|
||||
/// Returns the [User] model if successful, null if Google sign-in was cancelled.
|
||||
/// Throws an exception if authentication fails.
|
||||
Future<User?> signUpWithGoogle(String phoneNumber) async {
|
||||
Future<User?> signUpWithGoogle(
|
||||
String phoneNumber,
|
||||
String name,
|
||||
String firstname,
|
||||
) async {
|
||||
try {
|
||||
final firebaseUser = await _authService.signInWithGoogle();
|
||||
|
||||
@@ -132,8 +136,8 @@ class AuthRepository {
|
||||
final user = User(
|
||||
id: firebaseUser.user!.uid,
|
||||
email: firebaseUser.user!.email ?? '',
|
||||
nom: '',
|
||||
prenom: firebaseUser.user!.displayName ?? 'User',
|
||||
nom: name,
|
||||
prenom: firstname,
|
||||
phoneNumber: phoneNumber,
|
||||
profilePictureUrl: firebaseUser.user!.photoURL ?? 'Unknown',
|
||||
platform: 'google',
|
||||
@@ -171,7 +175,11 @@ class AuthRepository {
|
||||
///
|
||||
/// Returns the [User] model if successful, null if Apple sign-in was cancelled.
|
||||
/// Throws an exception if authentication fails.
|
||||
Future<User?> signUpWithApple(String phoneNumber) async {
|
||||
Future<User?> signUpWithApple(
|
||||
String phoneNumber,
|
||||
String name,
|
||||
String firstname,
|
||||
) async {
|
||||
try {
|
||||
final firebaseUser = await _authService.signInWithApple();
|
||||
|
||||
@@ -185,8 +193,8 @@ class AuthRepository {
|
||||
final user = User(
|
||||
id: firebaseUser.user!.uid,
|
||||
email: firebaseUser.user!.email ?? '',
|
||||
nom: '',
|
||||
prenom: firebaseUser.user!.displayName ?? 'User',
|
||||
nom: name,
|
||||
prenom: firstname,
|
||||
phoneNumber: phoneNumber,
|
||||
profilePictureUrl: firebaseUser.user!.photoURL ?? 'Unknown',
|
||||
platform: 'apple',
|
||||
|
||||
Reference in New Issue
Block a user