Enhance user authentication handling by adding authMethod to UserModel and updating ProfileContent to display authentication method details.

This commit is contained in:
Van Leemput Dayron
2025-11-13 14:46:21 +01:00
parent dd8de46e71
commit 0971b4cb3d
3 changed files with 105 additions and 13 deletions

View File

@@ -72,15 +72,19 @@ class UserModel {
/// User's last name (optional).
final String? nom;
/// Platform used for authentication (e.g., 'google', 'apple', 'email').
final String? authMethod;
/// Creates a new [UserModel] instance.
///
/// [id], [email], and [prenom] are required fields.
/// [nom] is optional and can be null.
/// [nom] and [authMethod] are optional and can be null.
UserModel({
required this.id,
required this.email,
required this.prenom,
this.nom,
this.authMethod,
});
/// Creates a [UserModel] instance from a JSON map.
@@ -93,6 +97,7 @@ class UserModel {
email: json['email'] ?? '',
prenom: json['prenom'] ?? 'Voyageur',
nom: json['nom'],
authMethod: json['authMethod'] ?? json['platform'],
);
}
@@ -105,6 +110,7 @@ class UserModel {
'email': email,
'prenom': prenom,
'nom': nom,
'authMethod': authMethod,
};
}
}

View File

@@ -16,6 +16,8 @@ class ProfileContent extends StatelessWidget {
Widget build(BuildContext context) {
return UserStateWrapper(
builder: (context, user) {
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
return Column(
children: [
// Section titre
@@ -76,6 +78,36 @@ class ProfileContent extends StatelessWidget {
user.email,
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
),
SizedBox(height: 12),
// Badge de méthode de connexion
Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: _getAuthMethodColor(user.authMethod, context),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
_getAuthMethodIcon(user.authMethod),
height: 16,
width: 16,
),
SizedBox(width: 8),
Text(
_getAuthMethodLabel(user.authMethod),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _getAuthMethodTextColor(user.authMethod, context),
),
),
],
),
),
],
),
),
@@ -91,6 +123,8 @@ class ProfileContent extends StatelessWidget {
},
),
// Afficher l'option de changement de mot de passe seulement pour email
if (isEmailAuth)
ListTile(
leading: Icon(Icons.lock),
title: Text('Changer le mot de passe'),
@@ -116,6 +150,54 @@ class ProfileContent extends StatelessWidget {
);
}
String _getAuthMethodLabel(String? authMethod) {
switch (authMethod) {
case 'apple':
return 'Connecté avec Apple';
case 'google':
return 'Connecté avec Google';
default:
return 'Connecté avec Email';
}
}
String _getAuthMethodIcon(String? authMethod) {
switch (authMethod) {
case 'apple':
return 'assets/icons/apple_white.png';
case 'google':
return 'assets/icons/google.png';
default:
return '';
}
}
Color _getAuthMethodColor(String? authMethod, BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
switch (authMethod) {
case 'apple':
return isDarkMode ? Colors.white : Colors.black87;
case 'google':
return isDarkMode ? Colors.white : Colors.black87;
default:
return isDarkMode ? Colors.white : Colors.blue;
}
}
Color _getAuthMethodTextColor(String? authMethod, BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
switch (authMethod) {
case 'apple':
return isDarkMode ? Colors.black87 : Colors.white;
case 'google':
return isDarkMode ? Colors.black87 : Colors.white;
default:
return isDarkMode ? Colors.black87 : Colors.white;
}
}
void _showEditProfileDialog(BuildContext context, user_state.UserModel user) {
final nomController = TextEditingController(text: user.nom);
final prenomController = TextEditingController(text: user.prenom);

View File

@@ -85,10 +85,10 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
Color platformColor = widget.platform == 'google'
? Colors.red
: Colors.black;
IconData platformIcon = widget.platform == 'google'
? Icons.g_mobiledata
: Icons.apple;
String platformName = widget.platform == 'google' ? 'Google' : 'Apple';
String platformIcon = widget.platform == 'google'
? 'assets/icons/google.png'
: 'assets/icons/apple_white.png';
return Container(
padding: const EdgeInsets.all(16),
@@ -103,7 +103,11 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
),
child: Row(
children: [
Icon(platformIcon, color: platformColor, size: 24),
Image.asset(
platformIcon,
height: 24,
width: 24,
),
const SizedBox(width: 8),
Text(
'Connecté avec $platformName',