diff --git a/lib/Screens/forgot_password.dart b/lib/Screens/forgot_password.dart index 4b33a14..04bcbab 100644 --- a/lib/Screens/forgot_password.dart +++ b/lib/Screens/forgot_password.dart @@ -48,11 +48,11 @@ class _ForgotPasswordFormState extends State { ), ); return true; - } - else { + } else { ScaffoldMessenger.of(context).showSnackBar( SnackBar( - content: Text('Erreur lors de la réinitialisation du mot de passe: ${response.statusCode}'), + content: Text( + 'Erreur lors de la réinitialisation du mot de passe: ${response.statusCode}'), backgroundColor: Colors.red, ), ); @@ -61,7 +61,8 @@ class _ForgotPasswordFormState extends State { } catch (e) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( - content: Text('Une erreur s\'est produite. Veuillez réessayer plus tard.'), + content: + Text('Une erreur s\'est produite. Veuillez réessayer plus tard.'), backgroundColor: Colors.red, ), ); @@ -113,30 +114,21 @@ class _ForgotPasswordFormState extends State { icon: Icons.person, hintName: 'Email', inputtype: TextInputType.text), - const SizedBox(height: 5.0), + const SizedBox(height: 10.0), GetTextFormField( controller: _conpassword, icon: Icons.lock, hintName: 'mot de passe', isObscureText: true, ), - const SizedBox(height: 5.0), + const SizedBox(height: 10.0), GetTextFormField( controller: _conconfpassword, icon: Icons.lock, hintName: 'confirmer mot de passe', isObscureText: true, ), - const SizedBox(height: 20.0), - TextButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => const LoginForm()), - ); - }, - child: const Text('Retourner à la page de connexion'), - ), + const SizedBox(height: 15.0), Container( margin: const EdgeInsets.all(30.0), width: double.infinity, @@ -146,17 +138,39 @@ class _ForgotPasswordFormState extends State { child: TextButton( onPressed: () async { if (await resetPassword()) { - await Future.delayed(const Duration(seconds: 1)); // Attendez 1 seconde - onResetPasswordSuccess(context); // Redirigez vers LoginForm uniquement si la réinitialisation du mot de passe a réussi + await Future.delayed( + const Duration(seconds: 1)); // Attendez 1 seconde + onResetPasswordSuccess( + context); // Redirigez vers LoginForm uniquement si la réinitialisation du mot de passe a réussi } }, child: const Text( 'Reinitialiser le mot de passe', - style: TextStyle( - color: Color.fromARGB(255, 197, 198, 243)), + style: + TextStyle(color: Color.fromARGB(255, 197, 198, 243), + fontSize: 18.0, + ), ), ), ), + const SizedBox(height: 80.0), + TextButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const LoginForm()), + ); + }, + child: const Text( + 'Retour à la page de connexion', + style: TextStyle( + fontSize: 20.0, + color: Colors.white70, + ), + ), + ), + ], ), ), diff --git a/lib/Screens/inscrire.dart b/lib/Screens/inscrire.dart index 0a295b0..83171c5 100644 --- a/lib/Screens/inscrire.dart +++ b/lib/Screens/inscrire.dart @@ -29,7 +29,7 @@ class _InscrireFormState extends State { width: 100.0, ), const Text( - "s'inscrire", + "Inscrivez-vous", style: TextStyle( fontWeight: FontWeight.bold, color: Colors.white, diff --git a/lib/Screens/login_form.dart b/lib/Screens/login_form.dart index dce2aaf..dba3571 100644 --- a/lib/Screens/login_form.dart +++ b/lib/Screens/login_form.dart @@ -1,6 +1,7 @@ // ignore_for_file: avoid_print import 'package:activmind_app/Screens/HomeForm.dart'; + // import 'package:activmind_app/Screens/home.dart'; import 'package:activmind_app/Screens/signup_form.dart'; import 'package:activmind_app/Screens/Calendar.dart'; @@ -39,17 +40,18 @@ class _LoginFormState extends State { final BuildContext currentContext = context; if (response.statusCode == 200) { // Save token to local storage - final token = jsonDecode(response.body)['token']; - await saveToken(token); + final token = jsonDecode(response.body)['token']; + await saveToken(token); + + // Extract username from response + final Map userData = jsonDecode(response.body); + final String username = userData['username']; - // Extract username from response - final Map userData = jsonDecode(response.body); - final String username = userData['username']; + // Update global variable with the username + var globalVariables = + Provider.of(context, listen: false); + globalVariables.user = username; - // Update global variable with the username - var globalVariables = Provider.of(context, listen: false); - globalVariables.user = username; - // ignore: use_build_context_synchronously Navigator.pushReplacement( currentContext, MaterialPageRoute(builder: (_) => const HomeForm())); @@ -70,11 +72,10 @@ class _LoginFormState extends State { // } } - Future saveToken(String token) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - await prefs.setString('token', token); -} + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString('token', token); + } @override Widget build(BuildContext context) { @@ -100,6 +101,7 @@ class _LoginFormState extends State { height: 100.0, width: 100.0, ), + const SizedBox(height: 20.0), const Text( 'se connecter', style: TextStyle( @@ -107,26 +109,35 @@ class _LoginFormState extends State { color: Colors.white, fontSize: 25.0), ), + const SizedBox(height: 10.0), GetTextFormField( controller: _conemail, icon: Icons.person, hintName: 'Email', inputtype: TextInputType.text), - const SizedBox(height: 5.0), + const SizedBox(height: 10.0), GetTextFormField( controller: _conpassword, icon: Icons.lock, hintName: 'mot de passe', isObscureText: true, ), + const SizedBox(height: 15.0), TextButton( onPressed: () { Navigator.push( context, - MaterialPageRoute(builder: (context) => const ForgotPasswordForm()), + MaterialPageRoute( + builder: (context) => const ForgotPasswordForm()), ); }, - child: Text('Mot de passe oublié ?'), + child: const Text( + 'Mot de passe oublié ?', + style: TextStyle( + color: Colors.white, + fontSize: 18.0, + fontWeight: FontWeight.bold), + ), ), Container( margin: const EdgeInsets.all(30.0), @@ -135,28 +146,45 @@ class _LoginFormState extends State { color: const Color.fromARGB(255, 76, 77, 166), borderRadius: BorderRadius.circular(30.0)), child: TextButton( - onPressed: login, + onPressed: login, + child: const Text( + 'connexion', + style: TextStyle( + color: Colors.white70, + fontSize: 20.0, + ), + ), + ), + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + // Centre les éléments verticalement + children: [ + const SizedBox(height: 100.0), + const Text( + "Vous n'avez pas encore de compte ?", + style: TextStyle( + fontWeight: FontWeight.bold, + color: Color.fromARGB(255, 76, 77, 166), + fontSize: 18.0), + ), + TextButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => const SignupForm())); + }, child: const Text( - 'connexion', + "Inscrivez-vous", style: TextStyle( - color: Color.fromARGB(255, 197, 198, 243)), - )), - ), - Center( - child: Container( - child: TextButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => const SignupForm())); - }, - child: const Text( - 'Inscrivez-vous', - style: TextStyle( - color: Color.fromARGB(255, 197, 198, 243)), - ))), - ), + color: Colors.white70, + fontSize: 18.0, + ), + ), + ), + ], + ) ], ), ), diff --git a/lib/Screens/signup_form.dart b/lib/Screens/signup_form.dart index 5f2a540..ed99379 100644 --- a/lib/Screens/signup_form.dart +++ b/lib/Screens/signup_form.dart @@ -2,6 +2,7 @@ import 'package:activmind_app/Screens/login_form.dart'; import 'package:activmind_app/common/comhelper.dart'; import 'package:flutter/material.dart'; import 'package:activmind_app/common/gen_text_form_field.dart'; + // ignore: depend_on_referenced_packages import 'package:http/http.dart' as http; import 'dart:convert'; @@ -24,60 +25,52 @@ class _SignupFormState extends State { final _conbirthdate = TextEditingController(); final _formKey = GlobalKey(); - List dropdownItems = ['Patient', 'Support', 'Assistent']; String? selectedDropdownItem; Future signUp() async { final form = _formKey.currentState; String email = _conemail.text; - String password1= _conpassword.text; + String password1 = _conpassword.text; String password2 = _conconfpassword.text; String firstName = _confirstname.text; String lastName = _conlastname.text; String birthDate = _conbirthdate.text; - - ToastContext toastContext = ToastContext(); - if (form!.validate()){ - if (password1 != password2){ - alterdialog(context, 'non concordance des mots de passe'); - } - else{ + if (form!.validate()) { + if (password1 != password2) { + alterdialog(context, 'non concordance des mots de passe'); + } else { final response = await http.post( - Uri.parse('http://10.0.2.2:8000/register/'), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: jsonEncode({ - 'email': _conemail.text, - 'password': _conpassword.text, - 'dropdownValue': selectedDropdownItem ?? '', - 'first_name' : _confirstname.text, - 'last_name' : _conlastname.text, - "date_of_birth" : _conbirthdate.text - }), - ); - - - if (response.statusCode == 200 || response.statusCode == 201) { - // ignore: use_build_context_synchronously - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (_) => const LoginForm(), - ), - (Route route) => false); - } else { - - - // ignore: use_build_context_synchronously - alterdialog(context, "La définition de l'utilisateur a rencontré une erreur"); - } + Uri.parse('http://10.0.2.2:8000/register/'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'email': _conemail.text, + 'password': _conpassword.text, + 'dropdownValue': selectedDropdownItem ?? '', + 'first_name': _confirstname.text, + 'last_name': _conlastname.text, + "date_of_birth": _conbirthdate.text + }), + ); + + if (response.statusCode == 200 || response.statusCode == 201) { + // ignore: use_build_context_synchronously + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (_) => const LoginForm(), + ), + (Route route) => false); + } else { + // ignore: use_build_context_synchronously + alterdialog(context, "Erreur dans l'inscription, veuillez réessayer"); + } } } - } @override @@ -103,8 +96,9 @@ class _SignupFormState extends State { height: 100.0, width: 100.0, ), + const SizedBox(height: 20.0), const Text( - "s'inscrire", + "Inscription", style: TextStyle( fontWeight: FontWeight.bold, color: Colors.white, @@ -132,7 +126,6 @@ class _SignupFormState extends State { isObscureText: true, ), const SizedBox(height: 5.0), - GetTextFormField( controller: _confirstname, icon: Icons.person, @@ -153,18 +146,15 @@ class _SignupFormState extends State { hintName: 'Date de naissance *', inputtype: TextInputType.text, ), - - const SizedBox(height: 5.0), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( - "type d'utilisateur:", + "type d'utilisateur * :", style: TextStyle( color: Color.fromARGB(255, 6, 6, 6), fontSize: 16.0, - ), ), const SizedBox(width: 10.0), @@ -177,9 +167,11 @@ class _SignupFormState extends State { child: Text( value, style: TextStyle( - color: value == selectedDropdownItem ? Colors.white : Colors.black, - ), + color: value == selectedDropdownItem + ? Colors.white + : Colors.black, ), + ), ); }).toList(), onChanged: (String? newValue) { @@ -193,33 +185,39 @@ class _SignupFormState extends State { const SizedBox(height: 20.0), ElevatedButton( style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, backgroundColor: const Color.fromARGB(255, 76, 77, 166), + foregroundColor: Colors.white, + backgroundColor: const Color.fromARGB(255, 76, 77, 166), ), - onPressed: signUp, - child: const Text('soumettre'), + onPressed: signUp, + child: const Text('Enregistrer'), ), const SizedBox(height: 20.0), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('vous avez une compte?'), - TextButton( - onPressed: () { - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (_) => const LoginForm(), - ), - (Route route) => false); - }, - child: const Text( - 'connectez-vous', - style: TextStyle( - color: Color.fromARGB(255, 197, 198, 243)), - )) - ], - ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'vous avez une compte?', + style: TextStyle( + fontSize: 18.0, fontWeight: FontWeight.w400), + ), + TextButton( + onPressed: () { + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (_) => const LoginForm(), + ), + (Route route) => false); + }, + child: const Text( + 'connectez-vous', + style: TextStyle( + color: Color.fromARGB(255, 197, 198, 243), + fontSize: 18.0, + ), + ), + ), + ], ), ], ), @@ -229,4 +227,4 @@ class _SignupFormState extends State { ), ); } -} \ No newline at end of file +}