Browse Source

Merge pull request #148 from ente-io/bugfix_ios

Active session bug fixes
Vishnu Mohandas 3 years ago
parent
commit
526043f687

+ 2 - 1
lib/ui/lock_screen.dart

@@ -44,7 +44,8 @@ class _LockScreenState extends State<LockScreen> {
   Future<void> _showLockScreen() async {
     _logger.info("Showing lockscreen");
     try {
-      final result = await requestAuthentication();
+      final result = await requestAuthentication(
+          "please authenticate to view your memories");
       if (result) {
         AppLock.of(context).didUnlock();
       }

+ 19 - 4
lib/ui/sessions_page.dart

@@ -1,11 +1,13 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
+import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/models/sessions.dart';
 import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/utils/date_time_util.dart';
 import 'package:photos/utils/dialog_util.dart';
+import 'package:photos/utils/toast_util.dart';
 
 class SessionsPage extends StatefulWidget {
   SessionsPage({Key key}) : super(key: key);
@@ -16,6 +18,7 @@ class SessionsPage extends StatefulWidget {
 
 class _SessionsPageState extends State<SessionsPage> {
   Sessions _sessions;
+  final Logger _logger = Logger("SessionsPageState");
 
   @override
   void initState() {
@@ -101,13 +104,25 @@ class _SessionsPageState extends State<SessionsPage> {
   Future<void> _terminateSession(Session session) async {
     final dialog = createProgressDialog(context, "please wait...");
     await dialog.show();
-    await UserService.instance.terminateSession(session.token);
-    await _fetchActiveSessions();
-    await dialog.hide();
+    try {
+      await UserService.instance.terminateSession(session.token);
+      await _fetchActiveSessions();
+      await dialog.hide();
+    } catch (e, s) {
+      await dialog.hide();
+      _logger.severe('failed to terminate', e, s);
+      showErrorDialog(
+          context, 'oops', "something went wrong, please try again");
+    }
   }
 
   Future<void> _fetchActiveSessions() async {
-    _sessions = await UserService.instance.getActiveSessions();
+    _sessions = await UserService.instance
+        .getActiveSessions()
+        .onError((error, stackTrace) {
+      showToast("failed to fetch active sessions");
+      throw error;
+    });
     _sessions.sessions.sort((first, second) {
       return second.lastUsedTime.compareTo(first.lastUsedTime);
     });

+ 9 - 8
lib/ui/settings/account_section_widget.dart

@@ -2,7 +2,6 @@ import 'dart:io';
 
 import 'package:flutter/material.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
-import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/app_lock.dart';
@@ -57,12 +56,12 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
           behavior: HitTestBehavior.translucent,
           onTap: () async {
             AppLock.of(context).setEnabled(false);
-            final result = await requestAuthentication();
+            String reason = "please authenticate to view your recovery key";
+            final result = await requestAuthentication(reason);
             AppLock.of(context)
                 .setEnabled(Configuration.instance.shouldShowLockScreen());
             if (!result) {
-              Logger("harami").info("Showing toast");
-              showToast("please authenticate to view your recovery key");
+              showToast(reason);
               return;
             }
 
@@ -96,11 +95,12 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
           behavior: HitTestBehavior.translucent,
           onTap: () async {
             AppLock.of(context).setEnabled(false);
-            final result = await requestAuthentication();
+            String reason = "please authenticate to change your email";
+            final result = await requestAuthentication(reason);
             AppLock.of(context)
                 .setEnabled(Configuration.instance.shouldShowLockScreen());
             if (!result) {
-              showToast("please authenticate to change your email");
+              showToast(reason);
               return;
             }
             showDialog(
@@ -124,11 +124,12 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
           behavior: HitTestBehavior.translucent,
           onTap: () async {
             AppLock.of(context).setEnabled(false);
-            final result = await requestAuthentication();
+            String reason = "please authenticate to change your password";
+            final result = await requestAuthentication(reason);
             AppLock.of(context)
                 .setEnabled(Configuration.instance.shouldShowLockScreen());
             if (!result) {
-              showToast("please authenticate to change your password");
+              showToast(reason);
               return;
             }
             Navigator.of(context).push(

+ 6 - 4
lib/ui/settings/security_section_widget.dart

@@ -71,12 +71,13 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
                         value: snapshot.data,
                         onChanged: (value) async {
                           AppLock.of(context).setEnabled(false);
-                          final result = await requestAuthentication();
+                          String reason =
+                              "please authenticate to configure two-factor authentication";
+                          final result = await requestAuthentication(reason);
                           AppLock.of(context).setEnabled(
                               Configuration.instance.shouldShowLockScreen());
                           if (!result) {
-                            showToast(
-                                "please authenticate to configure two-factor authentication");
+                            showToast(reason);
                             return;
                           }
                           if (value) {
@@ -117,7 +118,8 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
               value: _config.shouldShowLockScreen(),
               onChanged: (value) async {
                 AppLock.of(context).disable();
-                final result = await requestAuthentication();
+                final result = await requestAuthentication(
+                    "please authenticate to change lockscreen setting");
                 if (result) {
                   AppLock.of(context).setEnabled(value);
                   _config.setShouldShowLockScreen(value);

+ 2 - 2
lib/utils/auth_util.dart

@@ -2,11 +2,11 @@ import 'package:local_auth/auth_strings.dart';
 import 'package:local_auth/local_auth.dart';
 import 'package:logging/logging.dart';
 
-Future<bool> requestAuthentication([String reason]) async {
+Future<bool> requestAuthentication(String reason) async {
   Logger("AuthUtil").info("Requesting authentication");
   await LocalAuthentication().stopAuthentication();
   return await LocalAuthentication().authenticate(
-    localizedReason: reason ?? "please authenticate to view your memories",
+    localizedReason: reason,
     androidAuthStrings: AndroidAuthMessages(
       biometricHint: "verify identity",
       biometricNotRecognized: "not recognized, try again",