Ver Fonte

removed commented code + bug fix

ashilkn há 2 anos atrás
pai
commit
c1da25fa7a

+ 8 - 2
lib/services/user_service.dart

@@ -849,7 +849,10 @@ class UserService {
     }
   }
 
-  localAuthenticationService(BuildContext context, String reason) async {
+  Future<bool> localAuthenticationService(
+    BuildContext context,
+    String reason,
+  ) async {
     if (await LocalAuthentication().isDeviceSupported()) {
       AppLock.of(context).setEnabled(false);
       final result = await requestAuthentication(reason);
@@ -858,9 +861,12 @@ class UserService {
       );
       if (!result) {
         showToast(context, reason);
-        return;
+        return false;
+      } else {
+        return true;
       }
     }
+    return true;
   }
 
   Future<void> _saveConfiguration(Response response) async {

+ 23 - 32
lib/ui/account/delete_account_page.dart

@@ -141,43 +141,34 @@ class DeleteAccountPage extends StatelessWidget {
     BuildContext context,
     DeleteChallengeResponse response,
   ) async {
-    await UserService.instance.localAuthenticationService(
+    final hasAuthenticatedOrNoLocalAuth =
+        await UserService.instance.localAuthenticationService(
       context,
       "Please authenticate to initiate account deletion",
     );
-    // if (await LocalAuthentication().isDeviceSupported()) {
-    //   AppLock.of(context).setEnabled(false);
-    //   String reason = "Please authenticate to initiate account deletion";
-    //   final result = await requestAuthentication(reason);
-    //   AppLock.of(context).setEnabled(
-    //     Configuration.instance.shouldShowLockScreen(),
-    //   );
-    //   if (!result) {
-    //     showToast(context, reason);
-    //     return;
-    //   }
-    // }
 
-    final choice = await showChoiceDialog(
-      context,
-      'Are you sure you want to delete your account?',
-      'Your uploaded data will be scheduled for deletion, and your account '
-          'will be permanently deleted. \n\nThis action is not reversible.',
-      firstAction: 'Cancel',
-      secondAction: 'Delete',
-      firstActionColor: Theme.of(context).colorScheme.onSurface,
-      secondActionColor: Colors.red,
-    );
-    if (choice != DialogUserChoice.secondChoice) {
-      return;
+    if (hasAuthenticatedOrNoLocalAuth) {
+      final choice = await showChoiceDialog(
+        context,
+        'Are you sure you want to delete your account?',
+        'Your uploaded data will be scheduled for deletion, and your account '
+            'will be permanently deleted. \n\nThis action is not reversible.',
+        firstAction: 'Cancel',
+        secondAction: 'Delete',
+        firstActionColor: Theme.of(context).colorScheme.onSurface,
+        secondActionColor: Colors.red,
+      );
+      if (choice != DialogUserChoice.secondChoice) {
+        return;
+      }
+      final decryptChallenge = CryptoUtil.openSealSync(
+        Sodium.base642bin(response.encryptedChallenge),
+        Sodium.base642bin(Configuration.instance.getKeyAttributes().publicKey),
+        Configuration.instance.getSecretKey(),
+      );
+      final challengeResponseStr = utf8.decode(decryptChallenge);
+      await UserService.instance.deleteAccount(context, challengeResponseStr);
     }
-    final decryptChallenge = CryptoUtil.openSealSync(
-      Sodium.base642bin(response.encryptedChallenge),
-      Sodium.base642bin(Configuration.instance.getKeyAttributes().publicKey),
-      Configuration.instance.getSecretKey(),
-    );
-    final challengeResponseStr = utf8.decode(decryptChallenge);
-    await UserService.instance.deleteAccount(context, challengeResponseStr);
   }
 
   Future<void> _requestEmailForDeletion(BuildContext context) async {

+ 44 - 71
lib/ui/settings/account_section_widget.dart

@@ -35,39 +35,29 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            await UserService.instance.localAuthenticationService(
+            final hasAuthenticatedOrNoLocalAuth =
+                await UserService.instance.localAuthenticationService(
               context,
               "Please authenticate to view your recovery key",
             );
-            // if (await LocalAuthentication().isDeviceSupported()) {
-            //   AppLock.of(context).setEnabled(false);
-            //   const String reason =
-            //       "Please authenticate to view your recovery key";
-            //   final result = await requestAuthentication(reason);
-            //   AppLock.of(context)
-            //       .setEnabled(Configuration.instance.shouldShowLockScreen());
-            //   if (!result) {
-            //     showToast(context, reason);
-            //     return;
-            //   }
-            // }
-
-            String recoveryKey;
-            try {
-              recoveryKey = await _getOrCreateRecoveryKey();
-            } catch (e) {
-              showGenericErrorDialog(context);
-              return;
+            if (hasAuthenticatedOrNoLocalAuth) {
+              String recoveryKey;
+              try {
+                recoveryKey = await _getOrCreateRecoveryKey();
+              } catch (e) {
+                showGenericErrorDialog(context);
+                return;
+              }
+              routeToPage(
+                context,
+                RecoveryKeyPage(
+                  recoveryKey,
+                  "OK",
+                  showAppBar: true,
+                  onDone: () {},
+                ),
+              );
             }
-            routeToPage(
-              context,
-              RecoveryKeyPage(
-                recoveryKey,
-                "OK",
-                showAppBar: true,
-                onDone: () {},
-              ),
-            );
           },
           child: const SettingsTextItem(
             text: "Recovery key",
@@ -78,29 +68,21 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            await UserService.instance.localAuthenticationService(
+            final hasAuthenticatedOrNoLocalAuth =
+                await UserService.instance.localAuthenticationService(
               context,
               "Please authenticate to change your email",
             );
-            // if (await LocalAuthentication().isDeviceSupported()) {
-            //   AppLock.of(context).setEnabled(false);
-            //   const String reason = "Please authenticate to change your email";
-            //   final result = await requestAuthentication(reason);
-            //   AppLock.of(context)
-            //       .setEnabled(Configuration.instance.shouldShowLockScreen());
-            //   if (!result) {
-            //     showToast(context, reason);
-            //     return;
-            //   }
-            // }
-            showDialog(
-              context: context,
-              builder: (BuildContext context) {
-                return const ChangeEmailDialog();
-              },
-              barrierColor: Colors.black.withOpacity(0.85),
-              barrierDismissible: false,
-            );
+            if (hasAuthenticatedOrNoLocalAuth) {
+              showDialog(
+                context: context,
+                builder: (BuildContext context) {
+                  return const ChangeEmailDialog();
+                },
+                barrierColor: Colors.black.withOpacity(0.85),
+                barrierDismissible: false,
+              );
+            }
           },
           child: const SettingsTextItem(
             text: "Change email",
@@ -111,31 +93,22 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            await UserService.instance.localAuthenticationService(
+            final hasAuthenticatedOrNoLocalAuth =
+                await UserService.instance.localAuthenticationService(
               context,
               "Please authenticate to change your password",
             );
-            // if (await LocalAuthentication().isDeviceSupported()) {
-            //   AppLock.of(context).setEnabled(false);
-            //   const String reason =
-            //       "Please authenticate to change your password";
-            //   final result = await requestAuthentication(reason);
-            //   AppLock.of(context)
-            //       .setEnabled(Configuration.instance.shouldShowLockScreen());
-            //   if (!result) {
-            //     showToast(context, reason);
-            //     return;
-            //   }
-            // }
-            Navigator.of(context).push(
-              MaterialPageRoute(
-                builder: (BuildContext context) {
-                  return const PasswordEntryPage(
-                    mode: PasswordEntryMode.update,
-                  );
-                },
-              ),
-            );
+            if (hasAuthenticatedOrNoLocalAuth) {
+              Navigator.of(context).push(
+                MaterialPageRoute(
+                  builder: (BuildContext context) {
+                    return const PasswordEntryPage(
+                      mode: PasswordEntryMode.update,
+                    );
+                  },
+                ),
+              );
+            }
           },
           child: const SettingsTextItem(
             text: "Change password",

+ 22 - 37
lib/ui/settings/security_section_widget.dart

@@ -27,9 +27,6 @@ class SecuritySectionWidget extends StatefulWidget {
 }
 
 class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
-  static const authToViewSessions =
-      "Please authenticate to view your active sessions";
-
   final _config = Configuration.instance;
 
   StreamSubscription<TwoFactorStatusChangeEvent> _twoFactorStatusChangeEvent;
@@ -83,27 +80,18 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
                       return Switch.adaptive(
                         value: snapshot.data,
                         onChanged: (value) async {
-                          await UserService.instance.localAuthenticationService(
+                          final hasAuthenticatedOrNoLocalAuth =
+                              await UserService.instance
+                                  .localAuthenticationService(
                             context,
                             "Please authenticate to configure two-factor authentication",
                           );
-                          // if (await LocalAuthentication().isDeviceSupported()) {
-                          //   AppLock.of(context).setEnabled(false);
-                          //   const String reason =
-                          //       "Please authenticate to configure two-factor authentication";
-                          //   final result = await requestAuthentication(reason);
-                          //   AppLock.of(context).setEnabled(
-                          //     Configuration.instance.shouldShowLockScreen(),
-                          //   );
-                          //   if (!result) {
-                          //     showToast(context, reason);
-                          //     return;
-                          //   }
-                          // }
-                          if (value) {
-                            UserService.instance.setupTwoFactor(context);
-                          } else {
-                            _disableTwoFactor();
+                          if (hasAuthenticatedOrNoLocalAuth) {
+                            if (value) {
+                              UserService.instance.setupTwoFactor(context);
+                            } else {
+                              _disableTwoFactor();
+                            }
                           }
                         },
                       );
@@ -264,23 +252,20 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
       GestureDetector(
         behavior: HitTestBehavior.translucent,
         onTap: () async {
-          await UserService.instance
-              .localAuthenticationService(context, authToViewSessions);
-          // AppLock.of(context).setEnabled(false);
-          // final result = await requestAuthentication(authToViewSessions);
-          // AppLock.of(context)
-          //     .setEnabled(Configuration.instance.shouldShowLockScreen());
-          // if (!result) {
-          //   showToast(context, authToViewSessions);
-          //   return;
-          // }
-          Navigator.of(context).push(
-            MaterialPageRoute(
-              builder: (BuildContext context) {
-                return const SessionsPage();
-              },
-            ),
+          final hasAuthenticatedOrNoLocalAuth =
+              await UserService.instance.localAuthenticationService(
+            context,
+            "Please authenticate to view your active sessions",
           );
+          if (hasAuthenticatedOrNoLocalAuth) {
+            Navigator.of(context).push(
+              MaterialPageRoute(
+                builder: (BuildContext context) {
+                  return const SessionsPage();
+                },
+              ),
+            );
+          }
         },
         child: const SettingsTextItem(
           text: "Active sessions",