Browse Source

Trigger email verification when emailMFA enabled

Neeraj Gupta 2 năm trước cách đây
mục cha
commit
1a21119a01

+ 5 - 0
lib/generated/intl/messages_en.dart

@@ -306,6 +306,9 @@ class MessageLookup extends MessageLookupByLibrary {
             "Ask your loved ones to share"),
         "atAFalloutShelter":
             MessageLookupByLibrary.simpleMessage("at a fallout shelter"),
+        "authToChangeEmailVerificationSetting":
+            MessageLookupByLibrary.simpleMessage(
+                "Please authenticate to change email verification"),
         "authToChangeLockscreenSetting": MessageLookupByLibrary.simpleMessage(
             "Please authenticate to change lockscreen setting"),
         "authToChangeYourEmail": MessageLookupByLibrary.simpleMessage(
@@ -561,6 +564,8 @@ class MessageLookup extends MessageLookupByLibrary {
         "email": MessageLookupByLibrary.simpleMessage("Email"),
         "emailChangedTo": m15,
         "emailNoEnteAccount": m16,
+        "emailVerificationToggle":
+            MessageLookupByLibrary.simpleMessage("Email verification"),
         "emailYourLogs":
             MessageLookupByLibrary.simpleMessage("Email your logs"),
         "empty": MessageLookupByLibrary.simpleMessage("Empty"),

+ 20 - 0
lib/generated/l10n.dart

@@ -3132,6 +3132,26 @@ class S {
     );
   }
 
+  /// `Email verification`
+  String get emailVerificationToggle {
+    return Intl.message(
+      'Email verification',
+      name: 'emailVerificationToggle',
+      desc: '',
+      args: [],
+    );
+  }
+
+  /// `Please authenticate to change email verification`
+  String get authToChangeEmailVerificationSetting {
+    return Intl.message(
+      'Please authenticate to change email verification',
+      name: 'authToChangeEmailVerificationSetting',
+      desc: '',
+      args: [],
+    );
+  }
+
   /// `Export your data`
   String get exportYourData {
     return Intl.message(

+ 2 - 0
lib/l10n/intl_en.arb

@@ -453,6 +453,8 @@
   "authToChangeYourEmail": "Please authenticate to change your email",
   "changePassword": "Change password",
   "authToChangeYourPassword": "Please authenticate to change your password",
+  "emailVerificationToggle": "Email verification",
+  "authToChangeEmailVerificationSetting": "Please authenticate to change email verification",
   "exportYourData": "Export your data",
   "logout": "Logout",
   "authToInitiateAccountDeletion": "Please authenticate to initiate account deletion",

+ 4 - 0
lib/models/api/user/srp.dart

@@ -5,6 +5,7 @@ class SetupSRPRequest {
   final String srpA;
   final bool isUpdate;
 
+
   SetupSRPRequest({
     required this.srpUserID,
     required this.srpSalt,
@@ -87,6 +88,7 @@ class SrpAttributes {
   final int memLimit;
   final int opsLimit;
   final String kekSalt;
+  final bool isEmailMFAEnabled;
 
   SrpAttributes({
     required this.srpUserID,
@@ -94,6 +96,7 @@ class SrpAttributes {
     required this.memLimit,
     required this.opsLimit,
     required this.kekSalt,
+    required this.isEmailMFAEnabled,
   });
 
   factory SrpAttributes.fromMap(Map<String, dynamic> map) {
@@ -103,6 +106,7 @@ class SrpAttributes {
       memLimit: map['attributes']['memLimit'],
       opsLimit: map['attributes']['opsLimit'],
       kekSalt: map['attributes']['kekSalt'],
+      isEmailMFAEnabled: map['attributes']['isEmailMFAEnabled'],
     );
   }
 }

+ 13 - 7
lib/ui/account/login_page.dart

@@ -5,6 +5,7 @@ import 'package:photos/core/configuration.dart';
 import "package:photos/core/errors.dart";
 import "package:photos/generated/l10n.dart";
 import "package:photos/l10n/l10n.dart";
+import "package:photos/models/api/user/srp.dart";
 import 'package:photos/services/user_service.dart';
 import "package:photos/ui/account/login_pwd_verification_page.dart";
 import 'package:photos/ui/common/dynamic_fab.dart';
@@ -63,22 +64,27 @@ class _LoginPageState extends State<LoginPage> {
         buttonText: S.of(context).logInLabel,
         onPressedFunction: () async {
           UserService.instance.setEmail(_email!);
+          SrpAttributes? attr;
+          bool isEmailVerificationEnabled = true;
           try {
-            final attr = await UserService.instance.getSrpAttributes(_email!);
+            attr = await UserService.instance.getSrpAttributes(_email!);
+            isEmailVerificationEnabled = attr.isEmailMFAEnabled;
+          } catch (e) {
+            if (e is! SrpSetupNotCompleteError) {
+              _logger.severe('Error getting SRP attributes', e);
+            }
+          }
+          if (attr != null && !isEmailVerificationEnabled) {
             Navigator.of(context).push(
               MaterialPageRoute(
                 builder: (BuildContext context) {
                   return LoginPasswordVerificationPage(
-                    srpAttributes: attr,
+                    srpAttributes: attr!,
                   );
                 },
               ),
             );
-          }
-          catch (e) {
-            if(e is! SrpSetupNotCompleteError) {
-              _logger.warning('Error getting SRP attributes', e);
-            }
+          } else {
             await UserService.instance
                 .sendOtt(context, _email!, isCreateAccountScreen: false);
           }