|
@@ -34,12 +34,16 @@ import 'package:photos/utils/crypto_util.dart';
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
|
|
import 'package:photos/utils/toast_util.dart';
|
|
|
+import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
class UserService {
|
|
|
+ static const keyHasEnabledTwoFactor = "has_enabled_two_factor";
|
|
|
final _dio = Network.instance.getDio();
|
|
|
final _enteDio = Network.instance.enteDio;
|
|
|
final _logger = Logger((UserService).toString());
|
|
|
final _config = Configuration.instance;
|
|
|
+ SharedPreferences _preferences;
|
|
|
+
|
|
|
ValueNotifier<String> emailValueNotifier;
|
|
|
|
|
|
UserService._privateConstructor();
|
|
@@ -49,6 +53,8 @@ class UserService {
|
|
|
Future<void> init() async {
|
|
|
emailValueNotifier =
|
|
|
ValueNotifier<String>(Configuration.instance.getEmail());
|
|
|
+ _preferences = await SharedPreferences.getInstance();
|
|
|
+ setTwoFactor(fetchTwoFactorStatus: true);
|
|
|
}
|
|
|
|
|
|
Future<void> sendOtt(
|
|
@@ -716,7 +722,7 @@ class UserService {
|
|
|
Future<bool> fetchTwoFactorStatus() async {
|
|
|
try {
|
|
|
final response = await _enteDio.get("/users/two-factor/status");
|
|
|
- Configuration.instance.setTwoFactor(value: response.data["status"]);
|
|
|
+ setTwoFactor(value: response.data["status"]);
|
|
|
return response.data["status"];
|
|
|
} catch (e) {
|
|
|
_logger.severe("Failed to fetch 2FA status", e);
|
|
@@ -784,4 +790,18 @@ class UserService {
|
|
|
await Configuration.instance.setToken(response.data["token"]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ Future<void> setTwoFactor({
|
|
|
+ bool value = false,
|
|
|
+ bool fetchTwoFactorStatus = false,
|
|
|
+ }) async {
|
|
|
+ if (fetchTwoFactorStatus) {
|
|
|
+ value = await UserService.instance.fetchTwoFactorStatus();
|
|
|
+ }
|
|
|
+ _preferences.setBool(keyHasEnabledTwoFactor, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool hasEnabledTwoFactor() {
|
|
|
+ return _preferences.getBool(keyHasEnabledTwoFactor);
|
|
|
+ }
|
|
|
}
|