Pārlūkot izejas kodu

Show correct err when verification code has expired

Neeraj Gupta 3 gadi atpakaļ
vecāks
revīzija
3f27c83abd

+ 1 - 0
l10n-missing-translation.json

@@ -2,6 +2,7 @@
   "hi": [
   "hi": [
     "sign_up",
     "sign_up",
     "log_in",
     "log_in",
+    "log_in_code_expired",
     "oops",
     "oops",
     "start_backup",
     "start_backup",
     "auth_session_expired",
     "auth_session_expired",

+ 1 - 0
lib/l10n/app_en.arb

@@ -4,6 +4,7 @@
     "description": "Text on the sign up button used during registration"
     "description": "Text on the sign up button used during registration"
   },
   },
   "log_in": "log in",
   "log_in": "log in",
+  "log_in_code_expired" : "your verification code has expired",
   "ok": "ok",
   "ok": "ok",
   "oops": "oops",
   "oops": "oops",
   "@oops": {
   "@oops": {

+ 18 - 5
lib/services/user_service.dart

@@ -177,16 +177,29 @@ class UserService {
               return page;
               return page;
             },
             },
           ),
           ),
-          (route) => route.isFirst,
+              (route) => route.isFirst,
         );
         );
       } else {
       } 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();
       await dialog.hide();
       _logger.severe(e);
       _logger.severe(e);
-      showErrorDialog(context, AppLocalizations.of(context).oops,
+      showErrorDialog(context, AppLocalizations
+          .of(context)
+          .oops,
           "verification failed, please try again");
           "verification failed, please try again");
     }
     }
   }
   }

+ 4 - 4
lib/utils/dialog_util.dart

@@ -25,7 +25,7 @@ ProgressDialog createProgressDialog(BuildContext context, String message) {
   return dialog;
   return dialog;
 }
 }
 
 
-void showErrorDialog(BuildContext context, String title, String content) {
+Future<dynamic> showErrorDialog(BuildContext context, String title, String content) {
   AlertDialog alert = AlertDialog(
   AlertDialog alert = AlertDialog(
     title: Text(title),
     title: Text(title),
     content: Text(content),
     content: Text(content),
@@ -39,7 +39,7 @@ void showErrorDialog(BuildContext context, String title, String content) {
     ],
     ],
   );
   );
 
 
-  showDialog(
+  return showDialog(
     context: context,
     context: context,
     builder: (BuildContext context) {
     builder: (BuildContext context) {
       return alert;
       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<dynamic> showGenericErrorDialog(BuildContext context) {
+  return showErrorDialog(context, "something went wrong", "please try again.");
 }
 }
 
 
 Future<T> showConfettiDialog<T>({
 Future<T> showConfettiDialog<T>({