Enhance user authentication handling by adding authMethod to UserModel and updating ProfileContent to display authentication method details.
This commit is contained in:
@@ -72,15 +72,19 @@ class UserModel {
|
|||||||
/// User's last name (optional).
|
/// User's last name (optional).
|
||||||
final String? nom;
|
final String? nom;
|
||||||
|
|
||||||
|
/// Platform used for authentication (e.g., 'google', 'apple', 'email').
|
||||||
|
final String? authMethod;
|
||||||
|
|
||||||
/// Creates a new [UserModel] instance.
|
/// Creates a new [UserModel] instance.
|
||||||
///
|
///
|
||||||
/// [id], [email], and [prenom] are required fields.
|
/// [id], [email], and [prenom] are required fields.
|
||||||
/// [nom] is optional and can be null.
|
/// [nom] and [authMethod] are optional and can be null.
|
||||||
UserModel({
|
UserModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.email,
|
required this.email,
|
||||||
required this.prenom,
|
required this.prenom,
|
||||||
this.nom,
|
this.nom,
|
||||||
|
this.authMethod,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates a [UserModel] instance from a JSON map.
|
/// Creates a [UserModel] instance from a JSON map.
|
||||||
@@ -93,6 +97,7 @@ class UserModel {
|
|||||||
email: json['email'] ?? '',
|
email: json['email'] ?? '',
|
||||||
prenom: json['prenom'] ?? 'Voyageur',
|
prenom: json['prenom'] ?? 'Voyageur',
|
||||||
nom: json['nom'],
|
nom: json['nom'],
|
||||||
|
authMethod: json['authMethod'] ?? json['platform'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +110,7 @@ class UserModel {
|
|||||||
'email': email,
|
'email': email,
|
||||||
'prenom': prenom,
|
'prenom': prenom,
|
||||||
'nom': nom,
|
'nom': nom,
|
||||||
|
'authMethod': authMethod,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class ProfileContent extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return UserStateWrapper(
|
return UserStateWrapper(
|
||||||
builder: (context, user) {
|
builder: (context, user) {
|
||||||
|
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// Section titre
|
// Section titre
|
||||||
@@ -76,6 +78,36 @@ class ProfileContent extends StatelessWidget {
|
|||||||
user.email,
|
user.email,
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
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(
|
// Afficher l'option de changement de mot de passe seulement pour email
|
||||||
leading: Icon(Icons.lock),
|
if (isEmailAuth)
|
||||||
title: Text('Changer le mot de passe'),
|
ListTile(
|
||||||
trailing: Icon(Icons.arrow_forward_ios),
|
leading: Icon(Icons.lock),
|
||||||
onTap: () {
|
title: Text('Changer le mot de passe'),
|
||||||
_showChangePasswordDialog(context, user);
|
trailing: Icon(Icons.arrow_forward_ios),
|
||||||
},
|
onTap: () {
|
||||||
),
|
_showChangePasswordDialog(context, user);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
Divider(),
|
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) {
|
void _showEditProfileDialog(BuildContext context, user_state.UserModel user) {
|
||||||
final nomController = TextEditingController(text: user.nom);
|
final nomController = TextEditingController(text: user.nom);
|
||||||
final prenomController = TextEditingController(text: user.prenom);
|
final prenomController = TextEditingController(text: user.prenom);
|
||||||
|
|||||||
@@ -85,10 +85,10 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
|||||||
Color platformColor = widget.platform == 'google'
|
Color platformColor = widget.platform == 'google'
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: Colors.black;
|
: Colors.black;
|
||||||
IconData platformIcon = widget.platform == 'google'
|
|
||||||
? Icons.g_mobiledata
|
|
||||||
: Icons.apple;
|
|
||||||
String platformName = widget.platform == 'google' ? 'Google' : 'Apple';
|
String platformName = widget.platform == 'google' ? 'Google' : 'Apple';
|
||||||
|
String platformIcon = widget.platform == 'google'
|
||||||
|
? 'assets/icons/google.png'
|
||||||
|
: 'assets/icons/apple_white.png';
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@@ -103,7 +103,11 @@ class _SignUpPlatformContentState extends State<SignUpPlatformContent> {
|
|||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(platformIcon, color: platformColor, size: 24),
|
Image.asset(
|
||||||
|
platformIcon,
|
||||||
|
height: 24,
|
||||||
|
width: 24,
|
||||||
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
'Connecté avec $platformName',
|
'Connecté avec $platformName',
|
||||||
|
|||||||
Reference in New Issue
Block a user