fix: Make login page okay to look at
This commit is contained in:
parent
ef641d4023
commit
72d235b35b
3 changed files with 103 additions and 34 deletions
|
|
@ -1 +1 @@
|
||||||
const apiBasePath = "bal.ueauvergne.fr";
|
const apiBasePath = "bal.ueauvergne.fr/api";
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import 'package:seshat/ui/home_page/home_page.dart';
|
||||||
import 'package:seshat/ui/sell_page/sell_page.dart';
|
import 'package:seshat/ui/sell_page/sell_page.dart';
|
||||||
|
|
||||||
GoRouter router(AuthRepository authRepository) => GoRouter(
|
GoRouter router(AuthRepository authRepository) => GoRouter(
|
||||||
initialLocation: Routes.add,
|
initialLocation: Routes.login,
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
final loggedIn = await context.read<AuthRepository>().isLoggedIn;
|
final loggedIn = await context.read<AuthRepository>().isLoggedIn;
|
||||||
final logginIn = state.matchedLocation == Routes.login;
|
final logginIn = state.matchedLocation == Routes.login;
|
||||||
|
|
@ -20,7 +20,7 @@ GoRouter router(AuthRepository authRepository) => GoRouter(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logginIn) {
|
if (logginIn) {
|
||||||
return Routes.add;
|
return Routes.login;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,10 @@ class LoginPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LoginPageState extends State<LoginPage> {
|
class _LoginPageState extends State<LoginPage> {
|
||||||
final TextEditingController _username = TextEditingController(
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||||
text: "ueauvergne",
|
String username = "";
|
||||||
);
|
String password = "";
|
||||||
final TextEditingController _password = TextEditingController(
|
bool hidePassword = true;
|
||||||
text: "ueauvergne",
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -42,27 +40,100 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Center(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
child: ListenableBuilder(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
listenable: widget.viewModel.login,
|
||||||
children: [
|
builder: (context, child) {
|
||||||
TextField(controller: _username),
|
return Form(
|
||||||
TextField(controller: _password),
|
key: _formKey,
|
||||||
ListenableBuilder(
|
child: SingleChildScrollView(
|
||||||
listenable: widget.viewModel.login,
|
child: SizedBox(
|
||||||
builder: (context, child) {
|
width: 300,
|
||||||
return FilledButton(
|
child: Column(
|
||||||
onPressed: () {
|
mainAxisSize: MainAxisSize.min,
|
||||||
widget.viewModel.login.execute((
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
_username.value.text,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
_password.value.text,
|
children: [
|
||||||
));
|
Text("Bienvenue", style: TextStyle(fontSize: 40)),
|
||||||
},
|
SizedBox(height: 50),
|
||||||
child: Text("Connexion"),
|
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."),
|
content: Text("Une erreur est survenue lors de la connexion."),
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: "Réessayer",
|
label: "Réessayer",
|
||||||
onPressed: () => widget.viewModel.login.execute((
|
onPressed: () =>
|
||||||
_username.value.text,
|
widget.viewModel.login.execute((username, password)),
|
||||||
_password.value.text,
|
|
||||||
)),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Reference in a new issue