From 3f27c83abda3b576515c522bf3bc564d44dd8b96 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta Date: Sat, 4 Sep 2021 15:51:07 +0530 Subject: [PATCH 1/2] Show correct err when verification code has expired --- l10n-missing-translation.json | 1 + lib/l10n/app_en.arb | 1 + lib/services/user_service.dart | 23 ++++++++++++++++++----- lib/utils/dialog_util.dart | 8 ++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/l10n-missing-translation.json b/l10n-missing-translation.json index 77ebe1bec..3abeaabd6 100644 --- a/l10n-missing-translation.json +++ b/l10n-missing-translation.json @@ -2,6 +2,7 @@ "hi": [ "sign_up", "log_in", + "log_in_code_expired", "oops", "start_backup", "auth_session_expired", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 42a6f0551..8fd46036e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -4,6 +4,7 @@ "description": "Text on the sign up button used during registration" }, "log_in": "log in", + "log_in_code_expired" : "your verification code has expired", "ok": "ok", "oops": "oops", "@oops": { diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index dc5e9b4f0..460b0a4dd 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -177,16 +177,29 @@ class UserService { return page; }, ), - (route) => route.isFirst, + (route) => route.isFirst, ); } else { - showErrorDialog(context, AppLocalizations.of(context).oops, - "verification failed, please try again"); + // should never reach here + throw Exception("unexpected response during email verification"); } - } catch (e) { + } on DioError catch (e) { + await dialog.hide(); + if (e.response != null && e.response.statusCode == 410) { + await showErrorDialog(context, AppLocalizations.of(context).oops, + AppLocalizations.of(context).log_in_code_expired); + Navigator.of(context).pop(); + } else { + showErrorDialog(context, "incorrect code", + "authentication failed, please try again"); + } + } + catch (e) { await dialog.hide(); _logger.severe(e); - showErrorDialog(context, AppLocalizations.of(context).oops, + showErrorDialog(context, AppLocalizations + .of(context) + .oops, "verification failed, please try again"); } } diff --git a/lib/utils/dialog_util.dart b/lib/utils/dialog_util.dart index 24a01ff46..5e0233a0c 100644 --- a/lib/utils/dialog_util.dart +++ b/lib/utils/dialog_util.dart @@ -25,7 +25,7 @@ ProgressDialog createProgressDialog(BuildContext context, String message) { return dialog; } -void showErrorDialog(BuildContext context, String title, String content) { +Future showErrorDialog(BuildContext context, String title, String content) { AlertDialog alert = AlertDialog( title: Text(title), content: Text(content), @@ -39,7 +39,7 @@ void showErrorDialog(BuildContext context, String title, String content) { ], ); - showDialog( + return showDialog( context: context, builder: (BuildContext context) { return alert; @@ -48,8 +48,8 @@ void showErrorDialog(BuildContext context, String title, String content) { ); } -void showGenericErrorDialog(BuildContext context) { - showErrorDialog(context, "something went wrong", "please try again."); +Future showGenericErrorDialog(BuildContext context) { + return showErrorDialog(context, "something went wrong", "please try again."); } Future showConfettiDialog({ From 3c8b06ad6a345faf847716e0adf0a96c59d44728 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta Date: Sat, 4 Sep 2021 15:51:54 +0530 Subject: [PATCH 2/2] Linter: replace FlatButton with TextButton --- lib/utils/dialog_util.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/dialog_util.dart b/lib/utils/dialog_util.dart index 5e0233a0c..b7b42b711 100644 --- a/lib/utils/dialog_util.dart +++ b/lib/utils/dialog_util.dart @@ -30,7 +30,7 @@ Future showErrorDialog(BuildContext context, String title, String conte title: Text(title), content: Text(content), actions: [ - FlatButton( + TextButton( child: Text("ok"), onPressed: () { Navigator.of(context, rootNavigator: true).pop('dialog');