Skip to content

Commit

Permalink
Clear login forms after login
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed Dec 25, 2023
1 parent 9b7509a commit c12c06a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 7 additions & 9 deletions uni/lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@ class LoginPageViewState extends State<LoginPageView> {
bool _obscurePasswordInput = true;
bool _loggingIn = false;

Future<void> _login(BuildContext context) async {
Future<void> _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,
);
Expand Down Expand Up @@ -164,7 +161,8 @@ class LoginPageViewState extends State<LoginPageView> {
bottom: queryData.size.height / 15,
),
),
createLogInButton(queryData, context, _login),
createLogInButton(queryData, context, _login,
usernameController, passwordController),
Padding(
padding: EdgeInsets.only(
bottom: queryData.size.height / 35,
Expand All @@ -176,7 +174,7 @@ class LoginPageViewState extends State<LoginPageView> {
bottom: queryData.size.height / 35,
),
),
createSafeLoginButton(context),
createTermsLink(context),
],
),
),
Expand Down Expand Up @@ -233,7 +231,7 @@ class LoginPageViewState extends State<LoginPageView> {
passwordController,
passwordFocus,
_toggleObscurePasswordInput,
() => _login(context),
() => _login,
obscurePasswordInput: _obscurePasswordInput,
),
Padding(
Expand Down
14 changes: 9 additions & 5 deletions uni/lib/view/login/widgets/inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c12c06a

Please sign in to comment.