浏览代码

Merge branch 'master' of github.com:ente-io/frame

Vishnu 4 年之前
父节点
当前提交
4f5755b5af
共有 3 个文件被更改,包括 28 次插入6 次删除
  1. 1 0
      lib/core/configuration.dart
  2. 25 0
      lib/services/user_service.dart
  3. 2 6
      lib/ui/settings/account_section_widget.dart

+ 1 - 0
lib/core/configuration.dart

@@ -22,6 +22,7 @@ import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/favorites_service.dart';
 import 'package:photos/services/memories_service.dart';
 import 'package:photos/services/sync_service.dart';
+import 'package:photos/services/user_service.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 import 'package:photos/utils/crypto_util.dart';
 

+ 25 - 0
lib/services/user_service.dart

@@ -90,6 +90,31 @@ class UserService {
     }
   }
 
+  Future<void> logout(BuildContext context) async {
+    final dialog = createProgressDialog(context, "logging out...");
+    await dialog.show();
+    try {
+      final response =
+          await _dio.post(_config.getHttpEndpoint() + "/users/logout",
+              options: Options(
+                headers: {
+                  "X-Auth-Token": _config.getToken(),
+                },
+              ));
+      if (response != null && response.statusCode == 200) {
+        await Configuration.instance.logout();
+        await dialog.hide();
+        Navigator.of(context).popUntil((route) => route.isFirst);
+      } else {
+        throw new Exception("log out action failed");
+      }
+    } catch (e) {
+      _logger.severe(e);
+      await dialog.hide();
+      showGenericErrorDialog(context);
+    }
+  }
+
   Future<void> verifyEmail(BuildContext context, String ott) async {
     final dialog = createProgressDialog(context, "please wait...");
     await dialog.show();

+ 2 - 6
lib/ui/settings/account_section_widget.dart

@@ -3,6 +3,7 @@ import 'dart:io';
 import 'package:flutter/material.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/services/billing_service.dart';
+import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/settings/settings_section_title.dart';
 import 'package:photos/ui/settings/settings_text_item.dart';
@@ -97,12 +98,7 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
                     ),
                     onPressed: () async {
                       Navigator.of(context, rootNavigator: true).pop('dialog');
-                      final dialog =
-                          createProgressDialog(context, "logging out...");
-                      await dialog.show();
-                      await Configuration.instance.logout();
-                      await dialog.hide();
-                      Navigator.of(context).popUntil((route) => route.isFirst);
+                      await UserService.instance.logout(context);
                     },
                   ),
                 ],