fix: Make login page okay to look at

This commit is contained in:
Alzalia 2025-08-08 01:36:35 +02:00
parent ef641d4023
commit 72d235b35b
3 changed files with 103 additions and 34 deletions

View file

@ -1 +1 @@
const apiBasePath = "bal.ueauvergne.fr";
const apiBasePath = "bal.ueauvergne.fr/api";

View file

@ -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<AuthRepository>().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;

View file

@ -13,12 +13,10 @@ class LoginPage extends StatefulWidget {
}
class _LoginPageState extends State<LoginPage> {
final TextEditingController _username = TextEditingController(
text: "ueauvergne",
);
final TextEditingController _password = TextEditingController(
text: "ueauvergne",
);
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String username = "";
String password = "";
bool hidePassword = true;
@override
void initState() {
@ -42,27 +40,100 @@ class _LoginPageState extends State<LoginPage> {
@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<LoginPage> {
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)),
),
),
);