Browse Source

Save the encryption preference to configuration

Vishnu Mohandas 4 years ago
parent
commit
b4940d4fdd
2 changed files with 11 additions and 0 deletions
  1. 9 0
      lib/core/configuration.dart
  2. 2 0
      lib/ui/sign_in_widget.dart

+ 9 - 0
lib/core/configuration.dart

@@ -10,6 +10,7 @@ class Configuration {
   static const usernameKey = "username";
   static const userIDKey = "user_id";
   static const passwordKey = "password";
+  static const hasOptedForE2EKey = "has_opted_for_e2e_encryption";
   static const keyKey = "key";
 
   SharedPreferences _preferences;
@@ -65,6 +66,14 @@ class Configuration {
     await _preferences.setString(passwordKey, password);
   }
 
+  void setOptInForE2E(bool hasOptedForE2E) async {
+    await _preferences.setBool(hasOptedForE2EKey, hasOptedForE2E);
+  }
+
+  bool hasOptedForE2E() {
+    return _preferences.getBool(hasOptedForE2EKey);
+  }
+
   void generateAndSaveKey(String passphrase) async {
     final key = CryptoUtil.createCryptoRandomString();
     await _preferences.setString(keyKey, CryptoUtil.encrypt(key, passphrase));

+ 2 - 0
lib/ui/sign_in_widget.dart

@@ -275,6 +275,7 @@ class SelectEncryptionLevelWidget extends StatelessWidget {
           child: Text('Use E2E encryption'),
           onPressed: () {
             Navigator.of(context).pop();
+            Configuration.instance.setOptInForE2E(true);
             _showEnterPassphraseDialog(context);
           },
         ),
@@ -282,6 +283,7 @@ class SelectEncryptionLevelWidget extends StatelessWidget {
           child: Text("Use encryption at rest"),
           onPressed: () {
             Navigator.of(context).pop();
+            Configuration.instance.setOptInForE2E(false);
             Bus.instance.fire(UserAuthenticatedEvent());
           },
         ),