From 0971b4cb3d6a8d6594af3d82f2e97f0d30654c1c Mon Sep 17 00:00:00 2001 From: Van Leemput Dayron Date: Thu, 13 Nov 2025 14:46:21 +0100 Subject: [PATCH] Enhance user authentication handling by adding authMethod to UserModel and updating ProfileContent to display authentication method details. --- lib/blocs/user/user_state.dart | 8 +- .../settings/profile/profile_content.dart | 98 +++++++++++++++++-- .../signup/sign_up_platform_content.dart | 12 ++- 3 files changed, 105 insertions(+), 13 deletions(-) diff --git a/lib/blocs/user/user_state.dart b/lib/blocs/user/user_state.dart index ac9698c..5594361 100644 --- a/lib/blocs/user/user_state.dart +++ b/lib/blocs/user/user_state.dart @@ -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, }; } } diff --git a/lib/components/settings/profile/profile_content.dart b/lib/components/settings/profile/profile_content.dart index 1b397c6..d9ac3d2 100644 --- a/lib/components/settings/profile/profile_content.dart +++ b/lib/components/settings/profile/profile_content.dart @@ -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,14 +123,16 @@ class ProfileContent extends StatelessWidget { }, ), - ListTile( - leading: Icon(Icons.lock), - title: Text('Changer le mot de passe'), - trailing: Icon(Icons.arrow_forward_ios), - onTap: () { - _showChangePasswordDialog(context, user); - }, - ), + // 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'), + trailing: Icon(Icons.arrow_forward_ios), + onTap: () { + _showChangePasswordDialog(context, user); + }, + ), Divider(), @@ -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); diff --git a/lib/components/signup/sign_up_platform_content.dart b/lib/components/signup/sign_up_platform_content.dart index 84c35b3..51dd946 100644 --- a/lib/components/signup/sign_up_platform_content.dart +++ b/lib/components/signup/sign_up_platform_content.dart @@ -85,10 +85,10 @@ class _SignUpPlatformContentState extends State { 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 { ), child: Row( children: [ - Icon(platformIcon, color: platformColor, size: 24), + Image.asset( + platformIcon, + height: 24, + width: 24, + ), const SizedBox(width: 8), Text( 'Connecté avec $platformName',