couleur page de login
This commit is contained in:
parent
beb2048a7a
commit
25abc65480
@ -35,18 +35,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||
try {
|
||||
final userCount = await AppDatabase.instance.getUserCount();
|
||||
print('Nombre d\'utilisateurs trouvés: $userCount'); // Debug
|
||||
|
||||
// Commentez cette partie pour permettre le login même sans utilisateurs
|
||||
/*
|
||||
if (userCount == 0) {
|
||||
if (mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const AccueilPage()),
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
} catch (error) {
|
||||
print('Erreur lors de la vérification du nombre d\'utilisateurs: $error');
|
||||
setState(() {
|
||||
@ -65,11 +53,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
Future<void> saveUserData(Users user, String role, int userId) async {
|
||||
try {
|
||||
// ✅ CORRECTION : Utiliser la nouvelle méthode du contrôleur
|
||||
// Le contrôleur se charge maintenant de tout (observable + SharedPreferences)
|
||||
userController.setUserWithCredentials(user, role, userId);
|
||||
|
||||
print('Utilisateur sauvegardé: ${user.username}, rôle: $role, id: $userId');
|
||||
print(
|
||||
'Utilisateur sauvegardé: ${user.username}, rôle: $role, id: $userId');
|
||||
} catch (error) {
|
||||
print('Erreur lors de la sauvegarde: $error');
|
||||
throw Exception('Erreur lors de la sauvegarde des données utilisateur');
|
||||
@ -82,10 +68,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||
final String username = _usernameController.text.trim();
|
||||
final String password = _passwordController.text.trim();
|
||||
|
||||
// Validation basique
|
||||
if (username.isEmpty || password.isEmpty) {
|
||||
setState(() {
|
||||
_errorMessage = 'Veuillez saisir le nom d\'utilisateur et le mot de passe';
|
||||
_errorMessage =
|
||||
'Veuillez saisir le nom d\'utilisateur et le mot de passe';
|
||||
_isErrorVisible = true;
|
||||
});
|
||||
return;
|
||||
@ -97,45 +83,22 @@ class _LoginPageState extends State<LoginPage> {
|
||||
});
|
||||
|
||||
try {
|
||||
print('Tentative de connexion pour: $username');
|
||||
|
||||
// Vérification de la connexion à la base de données
|
||||
final dbInstance = AppDatabase.instance;
|
||||
|
||||
// Test de connexion à la base
|
||||
try {
|
||||
final userCount = await dbInstance.getUserCount();
|
||||
print('Base de données accessible, $userCount utilisateurs trouvés');
|
||||
} catch (dbError) {
|
||||
throw Exception('Impossible d\'accéder à la base de données: $dbError');
|
||||
}
|
||||
|
||||
// Vérifier les identifiants
|
||||
bool isValidUser = await dbInstance.verifyUser(username, password);
|
||||
print('Résultat de la vérification: $isValidUser');
|
||||
|
||||
if (isValidUser) {
|
||||
// Récupérer les informations complètes de l'utilisateur
|
||||
Users user = await dbInstance.getUser(username);
|
||||
print('Utilisateur récupéré: ${user.username}');
|
||||
|
||||
// Récupérer les credentials
|
||||
Map<String, dynamic>? userCredentials =
|
||||
await dbInstance.getUserCredentials(username, password);
|
||||
|
||||
if (userCredentials != null) {
|
||||
print('Connexion réussie pour: ${user.username}');
|
||||
print('Rôle: ${userCredentials['role']}');
|
||||
print('ID: ${userCredentials['id']}');
|
||||
|
||||
// ✅ CORRECTION : Sauvegarder ET mettre à jour le contrôleur
|
||||
await saveUserData(
|
||||
user,
|
||||
userCredentials['role'] as String,
|
||||
userCredentials['id'] as int,
|
||||
);
|
||||
|
||||
// Navigation
|
||||
if (mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
@ -146,137 +109,189 @@ class _LoginPageState extends State<LoginPage> {
|
||||
throw Exception('Erreur lors de la récupération des credentials');
|
||||
}
|
||||
} else {
|
||||
print('Identifiants invalides pour: $username');
|
||||
setState(() {
|
||||
_errorMessage = 'Nom d\'utilisateur ou mot de passe invalide';
|
||||
_isErrorVisible = true;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
print('Erreur lors de la connexion: $error');
|
||||
setState(() {
|
||||
_errorMessage = 'Erreur de connexion: ${error.toString()}';
|
||||
_isErrorVisible = true;
|
||||
});
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color primaryBlue = const Color(0xFF0033A1);
|
||||
final Color accentRed = const Color(0xFFD70000);
|
||||
final Color secondaryBlue = const Color(0xFF1976D2);
|
||||
final Color primaryColor = primaryBlue;
|
||||
final Color accentColor = secondaryBlue;
|
||||
final Color cardColor = Colors.white;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'Login',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: const Color.fromARGB(255, 4, 54, 95),
|
||||
centerTitle: true,
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
body: ParticleBackground(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.5,
|
||||
height: MediaQuery.of(context).size.height * 0.8,
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
width: MediaQuery.of(context).size.width < 500
|
||||
? double.infinity
|
||||
: 400,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 24.0, vertical: 32.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.rectangle,
|
||||
color: cardColor.withOpacity(0.98),
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: primaryColor.withOpacity(0.2),
|
||||
blurRadius: 16,
|
||||
spreadRadius: 4,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: const Icon(
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 38,
|
||||
backgroundColor: accentColor.withOpacity(0.15),
|
||||
child: Icon(
|
||||
Icons.lock_outline,
|
||||
size: 100.0,
|
||||
color: Color.fromARGB(255, 4, 54, 95),
|
||||
color: accentColor,
|
||||
size: 50,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
'GUYCOM',
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 28,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Connectez-vous à votre compte',
|
||||
style: TextStyle(
|
||||
color: primaryColor.withOpacity(.8),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _usernameController,
|
||||
enabled: !_isLoading,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Username',
|
||||
prefixIcon: const Icon(Icons.person, color: Colors.blueAccent),
|
||||
labelText: 'Nom d\'utilisateur',
|
||||
labelStyle: TextStyle(
|
||||
color: primaryColor.withOpacity(0.7),
|
||||
),
|
||||
prefixIcon: Icon(Icons.person, color: accentColor),
|
||||
filled: true,
|
||||
fillColor: accentColor.withOpacity(0.045),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
borderSide: BorderSide(color: accentColor, width: 2),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
borderSide: BorderSide(color: accentColor, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
const SizedBox(height: 18.0),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
enabled: !_isLoading,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
prefixIcon: const Icon(Icons.lock, color: Colors.redAccent),
|
||||
labelText: 'Mot de passe',
|
||||
labelStyle: TextStyle(
|
||||
color: primaryColor.withOpacity(0.7),
|
||||
),
|
||||
prefixIcon: Icon(Icons.lock, color: accentColor),
|
||||
filled: true,
|
||||
fillColor: accentColor.withOpacity(0.045),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
borderSide: BorderSide(color: accentColor, width: 2),
|
||||
),
|
||||
),
|
||||
obscureText: true,
|
||||
onSubmitted: (_) => _login(),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
Visibility(
|
||||
visible: _isErrorVisible,
|
||||
child: Text(
|
||||
if (_isErrorVisible) ...[
|
||||
const SizedBox(height: 12.0),
|
||||
Text(
|
||||
_errorMessage,
|
||||
style: const TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 14,
|
||||
color: Colors.redAccent,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
],
|
||||
const SizedBox(height: 26.0),
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading ? null : _login,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF0015B7),
|
||||
elevation: 5.0,
|
||||
backgroundColor: accentColor,
|
||||
disabledBackgroundColor: accentColor.withOpacity(0.3),
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 7.0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
),
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
minimumSize: const Size(double.infinity, 52),
|
||||
),
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
strokeWidth: 2.5,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'Se connecter',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: .4,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Bouton de debug (à supprimer en production)
|
||||
if (_isErrorVisible)
|
||||
// Option debug, à enlever en prod
|
||||
if (_isErrorVisible) ...[
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
final count = await AppDatabase.instance.getUserCount();
|
||||
print('Debug: $count utilisateurs dans la base');
|
||||
final count =
|
||||
await AppDatabase.instance.getUserCount();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('$count utilisateurs trouvés')),
|
||||
SnackBar(
|
||||
content: Text('$count utilisateurs trouvés')),
|
||||
);
|
||||
} catch (e) {
|
||||
print('Debug error: $e');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Erreur: $e')),
|
||||
);
|
||||
@ -285,6 +300,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
child: const Text('Debug: Vérifier BDD'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user