Page de connexion OK
Manque la logique de mot de passe oublié
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:em2rp/views/widgets/auth/mail_textfield.dart';
|
||||
import 'package:em2rp/views/widgets/error_message.dart';
|
||||
import 'package:em2rp/views/widgets/auth/forgot_password_button.dart';
|
||||
import 'package:em2rp/views/widgets/image/big_image_left.dart';
|
||||
import 'package:em2rp/views/widgets/auth/login_button.dart';
|
||||
import 'package:em2rp/views/widgets/image/em2_logo_n_sur_b.dart';
|
||||
import 'package:em2rp/views/widgets/auth/password_textfield.dart';
|
||||
import 'package:em2rp/views/widgets/auth/welcome_text.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
@ -13,6 +21,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||
final _passwordController = TextEditingController();
|
||||
String _errorMessage = '';
|
||||
bool _isLoading = false;
|
||||
bool _obscurePassword = true;
|
||||
bool _highlightPasswordField = false;
|
||||
bool _highlightEmailField = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@ -25,82 +36,118 @@ class _LoginPageState extends State<LoginPage> {
|
||||
setState(() {
|
||||
_errorMessage = '';
|
||||
_isLoading = true;
|
||||
_highlightPasswordField = false;
|
||||
_highlightEmailField = false;
|
||||
});
|
||||
try {
|
||||
await FirebaseAuth.instance.signInWithEmailAndPassword(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
);
|
||||
// Navigation vers la page principale après connexion réussie (à implémenter)
|
||||
// Par exemple : Navigator.of(context).pushReplacementNamed('/home');
|
||||
Navigator.of(context).pushReplacementNamed('/calendar');
|
||||
print('Connexion réussie!');
|
||||
} on FirebaseAuthException catch (e) {
|
||||
setState(() {
|
||||
_errorMessage = "Erreur de connexion: ${e.message}";
|
||||
_isLoading = false;
|
||||
if (e.code == 'user-not-found' || e.code == 'wrong-password') {
|
||||
_errorMessage = "Email ou mot de passe incorrect.";
|
||||
_highlightPasswordField = true;
|
||||
_highlightEmailField = true;
|
||||
} else if (e.code == 'invalid-email') {
|
||||
_errorMessage = "Adresse email invalide.";
|
||||
_highlightEmailField = true;
|
||||
} else {
|
||||
_errorMessage = "Erreur de connexion. Veuillez réessayer.";
|
||||
}
|
||||
});
|
||||
print('Erreur de connexion: ${e.code} - ${e.message}');
|
||||
}
|
||||
}
|
||||
|
||||
void _togglePasswordVisibility() {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
}
|
||||
|
||||
void _forgotPassword() {
|
||||
// TODO: Implémenter la logique de mot de passe oublié
|
||||
print("Mot de passe oublié cliqué !");
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Connexion'),
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
// Pour éviter le débordement sur les petits écrans
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/EM2_NsurB.jpg',
|
||||
height: 150,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
'Bienvenue !',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Mot de passe',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading
|
||||
? null
|
||||
: _signInWithEmailAndPassword, // Désactiver pendant le chargement
|
||||
child: _isLoading
|
||||
? const CircularProgressIndicator() // Indicateur de chargement
|
||||
: const Text('Se connecter'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const SizedBox(height: 10),
|
||||
if (_errorMessage.isNotEmpty)
|
||||
Text(
|
||||
_errorMessage,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth > 900) {
|
||||
return _buildLargeScreenLayout(context);
|
||||
} else {
|
||||
return _buildSmallScreenLayout(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLargeScreenLayout(BuildContext context) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
flex: 6,
|
||||
child:
|
||||
const ImageSectionWidget(), // Utilise le composant ImageSection
|
||||
),
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 50.0, vertical: 30.0),
|
||||
child: _buildLoginForm(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSmallScreenLayout(BuildContext context) {
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: _buildLoginForm(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoginForm(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
const LogoWidget(), // Utilise le widget LogoWidget
|
||||
const SizedBox(height: 30),
|
||||
const WelcomeTextWidget(), // Utilise le widget WelcomeTextWidget
|
||||
const SizedBox(height: 40),
|
||||
EmailTextFieldWidget(
|
||||
emailController: _emailController,
|
||||
highlightEmailField: _highlightEmailField,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
PasswordTextFieldWidget(
|
||||
passwordController: _passwordController,
|
||||
obscurePassword: _obscurePassword,
|
||||
highlightPasswordField: _highlightPasswordField,
|
||||
onTogglePasswordVisibility: _togglePasswordVisibility,
|
||||
),
|
||||
ForgotPasswordButtonWidget(onPressed: _forgotPassword),
|
||||
const SizedBox(height: 30),
|
||||
LoginButtonWidget(
|
||||
isLoading: _isLoading,
|
||||
onPressed: _signInWithEmailAndPassword,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ErrorMessageWidget(errorMessage: _errorMessage),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user