diff --git a/lib/config/constants.dart b/lib/config/constants.dart index 4a189e7..52e6729 100644 --- a/lib/config/constants.dart +++ b/lib/config/constants.dart @@ -1 +1 @@ -const apiBasePath = "bal.ueauvergne.fr"; +const apiBasePath = "bal.ueauvergne.fr/api"; diff --git a/lib/routing/router.dart b/lib/routing/router.dart index 6f56d6a..3391732 100644 --- a/lib/routing/router.dart +++ b/lib/routing/router.dart @@ -10,7 +10,7 @@ import 'package:seshat/ui/home_page/home_page.dart'; import 'package:seshat/ui/sell_page/sell_page.dart'; GoRouter router(AuthRepository authRepository) => GoRouter( - initialLocation: Routes.add, + initialLocation: Routes.login, redirect: (context, state) async { final loggedIn = await context.read().isLoggedIn; final logginIn = state.matchedLocation == Routes.login; @@ -20,7 +20,7 @@ GoRouter router(AuthRepository authRepository) => GoRouter( } if (logginIn) { - return Routes.add; + return Routes.login; } return null; diff --git a/lib/ui/auth/widgets/login_page.dart b/lib/ui/auth/widgets/login_page.dart index f73bcad..7c162da 100644 --- a/lib/ui/auth/widgets/login_page.dart +++ b/lib/ui/auth/widgets/login_page.dart @@ -13,12 +13,10 @@ class LoginPage extends StatefulWidget { } class _LoginPageState extends State { - final TextEditingController _username = TextEditingController( - text: "ueauvergne", - ); - final TextEditingController _password = TextEditingController( - text: "ueauvergne", - ); + final GlobalKey _formKey = GlobalKey(); + String username = ""; + String password = ""; + bool hidePassword = true; @override void initState() { @@ -42,27 +40,100 @@ class _LoginPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - TextField(controller: _username), - TextField(controller: _password), - ListenableBuilder( - listenable: widget.viewModel.login, - builder: (context, child) { - return FilledButton( - onPressed: () { - widget.viewModel.login.execute(( - _username.value.text, - _password.value.text, - )); - }, - child: Text("Connexion"), - ); - }, - ), - ], + body: Center( + child: ListenableBuilder( + listenable: widget.viewModel.login, + builder: (context, child) { + return Form( + key: _formKey, + child: SingleChildScrollView( + child: SizedBox( + width: 300, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("Bienvenue", style: TextStyle(fontSize: 40)), + SizedBox(height: 50), + TextFormField( + decoration: InputDecoration( + labelText: "Identifiant de section", + border: OutlineInputBorder(), + ), + validator: (value) { + if (value == null || value.isEmpty) { + return "Veuillez entrer un identifiant"; + } + return null; + }, + onSaved: (newValue) { + username = newValue!; + }, + ), + SizedBox(height: 10), + TextFormField( + decoration: InputDecoration( + labelText: "Mot de passe", + border: OutlineInputBorder(), + suffixIcon: IconButton( + onPressed: () { + setState(() { + hidePassword = !hidePassword; + }); + }, + icon: Icon( + (hidePassword) + ? Icons.visibility + : Icons.visibility_off, + ), + ), + ), + obscureText: hidePassword, + enableSuggestions: false, + autocorrect: false, + validator: (value) { + if (value == null || value.isEmpty) { + return "Veuillez entrer un mot de passe"; + } + return null; + }, + onSaved: (newValue) { + password = newValue!; + }, + ), + SizedBox(height: 10), + ElevatedButton( + onPressed: () { + _formKey.currentState!.validate(); + _formKey.currentState!.save(); + widget.viewModel.login.execute((username, password)); + }, + child: Text("Valider"), + ), + ], + ), + ), + ), + ); + }, + ), + // TextField(controller: _username), + // TextField(controller: _password), + // ListenableBuilder( + // listenable: widget.viewModel.login, + // builder: (context, child) { + // return FilledButton( + // onPressed: () { + // widget.viewModel.login.execute(( + // _username.value.text, + // _password.value.text, + // )); + // }, + // child: Text("Connexion"), + // ); + // }, + // ), ), ); } @@ -80,10 +151,8 @@ class _LoginPageState extends State { content: Text("Une erreur est survenue lors de la connexion."), action: SnackBarAction( label: "Réessayer", - onPressed: () => widget.viewModel.login.execute(( - _username.value.text, - _password.value.text, - )), + onPressed: () => + widget.viewModel.login.execute((username, password)), ), ), );