From 9b5ada747f9d6249646cea0fa5e8dc0b7453e29b Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 6 Nov 2024 21:59:27 +0000 Subject: [PATCH 1/6] added internetError exception and failure reason --- packages/uni_app/lib/session/exception.dart | 1 + .../sigarra/endpoints/html/authentication/login/response.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/uni_app/lib/session/exception.dart b/packages/uni_app/lib/session/exception.dart index 712ceae75..e1fb9232f 100644 --- a/packages/uni_app/lib/session/exception.dart +++ b/packages/uni_app/lib/session/exception.dart @@ -1,4 +1,5 @@ enum AuthenticationExceptionType { + internetError, wrongCredentials, expiredCredentials, other, diff --git a/packages/uni_app/lib/sigarra/endpoints/html/authentication/login/response.dart b/packages/uni_app/lib/sigarra/endpoints/html/authentication/login/response.dart index 4399da48f..dc8a26db1 100644 --- a/packages/uni_app/lib/sigarra/endpoints/html/authentication/login/response.dart +++ b/packages/uni_app/lib/sigarra/endpoints/html/authentication/login/response.dart @@ -8,6 +8,7 @@ class LoginResponse extends SigarraResponse { enum LoginFailureReason { serverError, + internetError, wrongCredentials, expiredCredentials, blockedAccount, From 65782a45291e198b7ce62440f36ccbf8a70d4e02 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 6 Nov 2024 22:08:46 +0000 Subject: [PATCH 2/6] completed the credential request failure handling --- .../lib/session/flows/credentials/request.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/uni_app/lib/session/flows/credentials/request.dart b/packages/uni_app/lib/session/flows/credentials/request.dart index 727935b29..de2235395 100644 --- a/packages/uni_app/lib/session/flows/credentials/request.dart +++ b/packages/uni_app/lib/session/flows/credentials/request.dart @@ -1,4 +1,6 @@ +import 'dart:async'; import 'package:http/http.dart' as http; +import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:uni/controller/fetchers/faculties_fetcher.dart'; import 'package:uni/session/exception.dart'; import 'package:uni/session/flows/base/request.dart'; @@ -35,11 +37,21 @@ class CredentialsSessionRequest extends SessionRequest { 'Failed to authenticate user', AuthenticationExceptionType.expiredCredentials, ); - } else { + } else if (failureReason == LoginFailureReason.internetError) { + throw const AuthenticationException( + 'Failed to authenticate user', + AuthenticationExceptionType.internetError, + ); + } else if (failureReason == LoginFailureReason.wrongCredentials) { throw const AuthenticationException( 'Failed to authenticate user', AuthenticationExceptionType.wrongCredentials, ); + } else { + unawaited(Sentry.captureException(failureReason)); + throw const AuthenticationException( + 'Failed to authenticate user', + ); } } From cbc58403ab22c1034e863928283a886a7f630f1d Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 6 Nov 2024 22:16:41 +0000 Subject: [PATCH 3/6] removed previous login failure exceptions --- .../lib/model/entities/login_exceptions.dart | 11 ------- packages/uni_app/lib/view/login/login.dart | 30 +------------------ 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 packages/uni_app/lib/model/entities/login_exceptions.dart diff --git a/packages/uni_app/lib/model/entities/login_exceptions.dart b/packages/uni_app/lib/model/entities/login_exceptions.dart deleted file mode 100644 index d701801d4..000000000 --- a/packages/uni_app/lib/model/entities/login_exceptions.dart +++ /dev/null @@ -1,11 +0,0 @@ -class ExpiredCredentialsException implements Exception { - ExpiredCredentialsException(); -} - -class InternetStatusException implements Exception { - InternetStatusException(); -} - -class WrongCredentialsException implements Exception { - WrongCredentialsException(); -} diff --git a/packages/uni_app/lib/view/login/login.dart b/packages/uni_app/lib/view/login/login.dart index cab5cfcb2..e71ed068c 100644 --- a/packages/uni_app/lib/view/login/login.dart +++ b/packages/uni_app/lib/view/login/login.dart @@ -9,7 +9,6 @@ import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:uni/app_links/uni_app_links.dart'; import 'package:uni/controller/networking/url_launcher.dart'; import 'package:uni/generated/l10n.dart'; -import 'package:uni/model/entities/login_exceptions.dart'; import 'package:uni/model/providers/startup/session_provider.dart'; import 'package:uni/model/providers/state_providers.dart'; import 'package:uni/session/flows/credentials/initiator.dart'; @@ -99,37 +98,10 @@ class LoginPageViewState extends State _loggingIn = false; }); } - } catch (err, st) { + } catch (err) { setState(() { _loggingIn = false; }); - if (err is ExpiredCredentialsException) { - _updatePasswordDialog(); - } else if (err is InternetStatusException) { - if (mounted) { - unawaited( - ToastMessage.warning( - context, - S.of(context).internet_status_exception, - ), - ); - } - } else if (err is WrongCredentialsException) { - if (mounted) { - unawaited( - ToastMessage.error( - context, - S.of(context).wrong_credentials_exception, - ), - ); - } - } else { - Logger().e(err, stackTrace: st); - unawaited(Sentry.captureException(err, stackTrace: st)); - if (mounted) { - unawaited(ToastMessage.error(context, S.of(context).failed_login)); - } - } } } } From df48c3cc9de427fd2ed6a41dd111a8cec144b312 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 6 Nov 2024 22:36:16 +0000 Subject: [PATCH 4/6] removed update password dialog --- packages/uni_app/lib/view/login/login.dart | 43 ---------------------- 1 file changed, 43 deletions(-) diff --git a/packages/uni_app/lib/view/login/login.dart b/packages/uni_app/lib/view/login/login.dart index e71ed068c..370fa38eb 100644 --- a/packages/uni_app/lib/view/login/login.dart +++ b/packages/uni_app/lib/view/login/login.dart @@ -7,7 +7,6 @@ import 'package:logger/logger.dart'; import 'package:provider/provider.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:uni/app_links/uni_app_links.dart'; -import 'package:uni/controller/networking/url_launcher.dart'; import 'package:uni/generated/l10n.dart'; import 'package:uni/model/providers/startup/session_provider.dart'; import 'package:uni/model/providers/state_providers.dart'; @@ -336,46 +335,4 @@ class LoginPageViewState extends State }, ); } - - void _updatePasswordDialog() { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text(S.of(context).expired_password), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - S.of(context).pass_change_request, - textAlign: TextAlign.start, - style: Theme.of(context).textTheme.titleSmall, - ), - const SizedBox(height: 20), - Align( - alignment: Alignment.centerLeft, - child: Text( - S.of(context).change_prompt, - textAlign: TextAlign.start, - ), - ), - ], - ), - actions: [ - TextButton( - child: Text(S.of(context).cancel), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ElevatedButton( - child: Text(S.of(context).change), - onPressed: () => - launchUrlWithToast(context, 'https://self-id.up.pt/password'), - ), - ], - ); - }, - ); - } } From bc5ba1ca676c60f5082f759ce97ca84acfa7df5f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 9 Nov 2024 11:54:10 +0000 Subject: [PATCH 5/6] handled login exceptions with AuthenticationException --- .../session/flows/credentials/request.dart | 2 - packages/uni_app/lib/view/login/login.dart | 88 ++++++++++++++++++- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/packages/uni_app/lib/session/flows/credentials/request.dart b/packages/uni_app/lib/session/flows/credentials/request.dart index de2235395..cc658bd95 100644 --- a/packages/uni_app/lib/session/flows/credentials/request.dart +++ b/packages/uni_app/lib/session/flows/credentials/request.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'package:http/http.dart' as http; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:uni/controller/fetchers/faculties_fetcher.dart'; import 'package:uni/session/exception.dart'; import 'package:uni/session/flows/base/request.dart'; @@ -48,7 +47,6 @@ class CredentialsSessionRequest extends SessionRequest { AuthenticationExceptionType.wrongCredentials, ); } else { - unawaited(Sentry.captureException(failureReason)); throw const AuthenticationException( 'Failed to authenticate user', ); diff --git a/packages/uni_app/lib/view/login/login.dart b/packages/uni_app/lib/view/login/login.dart index 370fa38eb..9c1cbb45a 100644 --- a/packages/uni_app/lib/view/login/login.dart +++ b/packages/uni_app/lib/view/login/login.dart @@ -7,9 +7,11 @@ import 'package:logger/logger.dart'; import 'package:provider/provider.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:uni/app_links/uni_app_links.dart'; +import 'package:uni/controller/networking/url_launcher.dart'; import 'package:uni/generated/l10n.dart'; import 'package:uni/model/providers/startup/session_provider.dart'; import 'package:uni/model/providers/state_providers.dart'; +import 'package:uni/session/exception.dart'; import 'package:uni/session/flows/credentials/initiator.dart'; import 'package:uni/session/flows/federated/initiator.dart'; import 'package:uni/utils/constants.dart'; @@ -97,10 +99,52 @@ class LoginPageViewState extends State _loggingIn = false; }); } - } catch (err) { + } on AuthenticationException catch (err, st) { setState(() { _loggingIn = false; }); + + switch (err.type) { + case AuthenticationExceptionType.expiredCredentials: + _updatePasswordDialog(); + case AuthenticationExceptionType.internetError: + if (mounted) { + unawaited( + ToastMessage.warning( + context, + S.of(context).internet_status_exception, + ), + ); + } + case AuthenticationExceptionType.wrongCredentials: + if (mounted) { + unawaited( + ToastMessage.error( + context, + S.of(context).wrong_credentials_exception, + ), + ); + } + default: + Logger().e(err, stackTrace: st); + unawaited(Sentry.captureException(err, stackTrace: st)); + if (mounted) { + unawaited( + ToastMessage.error(context, S.of(context).failed_login), + ); + } + } + } + // Handles other unexpected exceptions + catch (err, st) { + setState(() { + _loggingIn = false; + }); + Logger().e(err, stackTrace: st); + unawaited(Sentry.captureException(err, stackTrace: st)); + if (mounted) { + unawaited(ToastMessage.error(context, S.of(context).failed_login)); + } } } } @@ -335,4 +379,46 @@ class LoginPageViewState extends State }, ); } + + void _updatePasswordDialog() { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text(S.of(context).expired_password), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + S.of(context).pass_change_request, + textAlign: TextAlign.start, + style: Theme.of(context).textTheme.titleSmall, + ), + const SizedBox(height: 20), + Align( + alignment: Alignment.centerLeft, + child: Text( + S.of(context).change_prompt, + textAlign: TextAlign.start, + ), + ), + ], + ), + actions: [ + TextButton( + child: Text(S.of(context).cancel), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ElevatedButton( + child: Text(S.of(context).change), + onPressed: () => + launchUrlWithToast(context, 'https://self-id.up.pt/password'), + ), + ], + ); + }, + ); + } } From e30a31c172775ee4f2020f04ac4d876c2dcdf8ca Mon Sep 17 00:00:00 2001 From: thePeras Date: Mon, 11 Nov 2024 15:21:14 +0000 Subject: [PATCH 6/6] Bump app version [no ci] --- packages/uni_app/app_version.txt | 2 +- packages/uni_app/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/uni_app/app_version.txt b/packages/uni_app/app_version.txt index 8d05f6a01..464eac0ff 100644 --- a/packages/uni_app/app_version.txt +++ b/packages/uni_app/app_version.txt @@ -1 +1 @@ -1.10.0-beta.35+338 +1.10.0-beta.36+339 diff --git a/packages/uni_app/pubspec.yaml b/packages/uni_app/pubspec.yaml index 7c5d3d057..a9d41f398 100644 --- a/packages/uni_app/pubspec.yaml +++ b/packages/uni_app/pubspec.yaml @@ -7,7 +7,7 @@ publish_to: "none" # We do not publish to pub.dev # To change it manually, override the value in app_version.txt. # The app version code is automatically also bumped by CI. # Do not change it manually. -version: 1.10.0-beta.35+338 +version: 1.10.0-beta.36+339 environment: sdk: ">=3.4.0 <4.0.0"