From c12c06ab11fd446f8947233f29d5499858c9153c Mon Sep 17 00:00:00 2001 From: Bruno Mendes Date: Mon, 25 Dec 2023 23:29:53 +0000 Subject: [PATCH] Clear login forms after login --- uni/lib/view/login/login.dart | 16 +++++++--------- uni/lib/view/login/widgets/inputs.dart | 14 +++++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/uni/lib/view/login/login.dart b/uni/lib/view/login/login.dart index 17d1076b7..51691f3de 100644 --- a/uni/lib/view/login/login.dart +++ b/uni/lib/view/login/login.dart @@ -42,22 +42,19 @@ class LoginPageViewState extends State { bool _obscurePasswordInput = true; bool _loggingIn = false; - Future _login(BuildContext context) async { + Future _login(String username, String password) async { final stateProviders = StateProviders.fromContext(context); final sessionProvider = stateProviders.sessionProvider; if (!_loggingIn && _formKey.currentState!.validate()) { - final user = usernameController.text.trim(); - final pass = passwordController.text.trim(); - try { setState(() { _loggingIn = true; }); await sessionProvider.postAuthentication( context, - user, - pass, + username, + password, faculties, persistentSession: _keepSignedIn, ); @@ -164,7 +161,8 @@ class LoginPageViewState extends State { bottom: queryData.size.height / 15, ), ), - createLogInButton(queryData, context, _login), + createLogInButton(queryData, context, _login, + usernameController, passwordController), Padding( padding: EdgeInsets.only( bottom: queryData.size.height / 35, @@ -176,7 +174,7 @@ class LoginPageViewState extends State { bottom: queryData.size.height / 35, ), ), - createSafeLoginButton(context), + createTermsLink(context), ], ), ), @@ -233,7 +231,7 @@ class LoginPageViewState extends State { passwordController, passwordFocus, _toggleObscurePasswordInput, - () => _login(context), + () => _login, obscurePasswordInput: _obscurePasswordInput, ), Padding( diff --git a/uni/lib/view/login/widgets/inputs.dart b/uni/lib/view/login/widgets/inputs.dart index b926e1831..856a6e3c5 100644 --- a/uni/lib/view/login/widgets/inputs.dart +++ b/uni/lib/view/login/widgets/inputs.dart @@ -93,7 +93,9 @@ Widget createSaveDataCheckBox( Widget createLogInButton( MediaQueryData queryData, BuildContext context, - void Function(BuildContext) login, + void Function(String, String) login, + TextEditingController usernameController, + TextEditingController passwordController, ) { return Padding( padding: EdgeInsets.only( @@ -113,7 +115,11 @@ Widget createLogInButton( if (!FocusScope.of(context).hasPrimaryFocus) { FocusScope.of(context).unfocus(); } - login(context); + final username = usernameController.text; + final password = passwordController.text; + login(username, password); + usernameController.clear(); + passwordController.clear(); }, child: Text( S.of(context).login, @@ -169,9 +175,7 @@ InputDecoration passwordFieldDecoration( ); } -/// Displays terms and conditions if the user is -/// logging in for the first time. -InkResponse createSafeLoginButton(BuildContext context) { +InkResponse createTermsLink(BuildContext context) { return InkResponse( onTap: () { _showLoginDetails(context);