Просмотр исходного кода

handled bugs related to when there is no device level authentication

ashilkn 2 лет назад
Родитель
Сommit
67597bf627

+ 13 - 9
lib/ui/account/delete_account_page.dart

@@ -2,6 +2,7 @@ import 'dart:convert';
 
 import 'package:flutter/material.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
+import 'package:local_auth/local_auth.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/models/delete_account.dart';
 import 'package:photos/services/user_service.dart';
@@ -144,16 +145,19 @@ class DeleteAccountPage extends StatelessWidget {
     BuildContext context,
     DeleteChallengeResponse response,
   ) async {
-    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;
+    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?',

+ 31 - 24
lib/ui/settings/account_section_widget.dart

@@ -1,6 +1,7 @@
 import 'package:expandable/expandable.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
+import 'package:local_auth/local_auth.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/account/change_email_dialog.dart';
@@ -39,14 +40,16 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            AppLock.of(context).setEnabled(false);
-            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;
+            if (await LocalAuthentication().isDeviceSupported()) {
+              AppLock.of(context).setEnabled(false);
+              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;
@@ -75,14 +78,16 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            AppLock.of(context).setEnabled(false);
-            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;
+            if (await LocalAuthentication().isDeviceSupported()) {
+              AppLock.of(context).setEnabled(false);
+              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,
@@ -102,14 +107,16 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
         GestureDetector(
           behavior: HitTestBehavior.translucent,
           onTap: () async {
-            AppLock.of(context).setEnabled(false);
-            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;
+            if (await LocalAuthentication().isDeviceSupported()) {
+              AppLock.of(context).setEnabled(false);
+              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(

+ 13 - 10
lib/ui/settings/security_section_widget.dart

@@ -4,6 +4,7 @@ import 'dart:io';
 import 'package:expandable/expandable.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_windowmanager/flutter_windowmanager.dart';
+import 'package:local_auth/local_auth.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/ente_theme_data.dart';
@@ -82,16 +83,18 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
                       return Switch.adaptive(
                         value: snapshot.data,
                         onChanged: (value) async {
-                          AppLock.of(context).setEnabled(false);
-                          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 (await LocalAuthentication().isDeviceSupported()) {
+                            AppLock.of(context).setEnabled(false);
+                            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);