From 0c80577f72b978948b1ac6ee3eea269b80ad4012 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 24 Jun 2021 10:46:19 -0700 Subject: [PATCH] Hide "Current Password" field for password-less accounts --- LIBCWTCH-GO.version | 2 +- lib/cwtch/cwtchNotifier.dart | 3 +- lib/model.dart | 13 +++++-- lib/views/addeditprofileview.dart | 4 +-- lib/widgets/profilerow.dart | 6 ++-- linux/flutter/generated_plugin_registrant.cc | 4 --- linux/flutter/generated_plugins.cmake | 1 - pubspec.lock | 35 +++++++++++++++++++ .../flutter/generated_plugin_registrant.cc | 3 -- windows/flutter/generated_plugins.cmake | 1 - 10 files changed, 54 insertions(+), 18 deletions(-) diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index 0bc6904..566981f 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -v0.0.2-104-gc1b7e4c-2021-06-22-23-59 \ No newline at end of file +v0.0.2-106-g69f14f9-2021-06-24-15-49 \ No newline at end of file diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 567202b..c3ebc61 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -37,7 +37,8 @@ class CwtchNotifier { appState.SetAppError(data["Error"]); break; case "NewPeer": - profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true"); + // if tag != v1-defaultPassword then it is either encrypted OR it is an unencrypted account created during pre-beta... + profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["tag"] != "v1-defaultPassword"); break; case "PeerCreated": profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState( diff --git a/lib/model.dart b/lib/model.dart index 60aa478..68a3fa2 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -38,10 +38,10 @@ class ProfileListState extends ChangeNotifier { List _profiles = []; int get num => _profiles.length; - void add(String onion, String name, String picture, String contactsJson, String serverJson, bool online) { + void add(String onion, String name, String picture, String contactsJson, String serverJson, bool online, bool encrypted) { var idx = _profiles.indexWhere((element) => element.onion == onion); if (idx == -1) { - _profiles.add(ProfileInfoState(onion: onion, nickname: name, imagePath: picture, contactsJson: contactsJson, serversJson: serverJson, online: online)); + _profiles.add(ProfileInfoState(onion: onion, nickname: name, imagePath: picture, contactsJson: contactsJson, serversJson: serverJson, online: online, encrypted: encrypted)); } else { _profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online); } @@ -177,6 +177,10 @@ class ProfileInfoState extends ChangeNotifier { int _unreadMessages = 0; bool _online = false; + // assume profiles are encrypted...this will be set to false + // in the constructor if the profile is encrypted with the defacto password. + bool _encrypted = true; + ProfileInfoState({ required this.onion, nickname = "", @@ -185,11 +189,13 @@ class ProfileInfoState extends ChangeNotifier { contactsJson = "", serversJson = "", online = false, + encrypted = true, }) { this._nickname = nickname; this._imagePath = imagePath; this._unreadMessages = unreadMessages; this._online = online; + this._encrypted = encrypted; if (contactsJson != null && contactsJson != "" && contactsJson != "null") { List contacts = jsonDecode(contactsJson); @@ -243,6 +249,9 @@ class ProfileInfoState extends ChangeNotifier { notifyListeners(); } + // Check encrypted status for profile info screen + bool get isEncrypted => this._encrypted; + String get nickname => this._nickname; set nickname(String newValue) { this._nickname = newValue; diff --git a/lib/views/addeditprofileview.dart b/lib/views/addeditprofileview.dart index 981385f..a493f56 100644 --- a/lib/views/addeditprofileview.dart +++ b/lib/views/addeditprofileview.dart @@ -155,7 +155,7 @@ class _AddEditProfileViewState extends State { visible: usePassword, child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Visibility( - visible: Provider.of(context, listen: false).onion.isNotEmpty, + visible: Provider.of(context, listen: false).onion.isNotEmpty && Provider.of(context).isEncrypted, child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ CwtchLabel(label: AppLocalizations.of(context)!.currentPasswordLabel), SizedBox( @@ -165,7 +165,7 @@ class _AddEditProfileViewState extends State { controller: ctrlrOldPass, validator: (value) { // Password field can be empty when just updating the profile, not on creation - if (Provider.of(context, listen: false).onion.isEmpty && value.isEmpty && usePassword) { + if (Provider.of(context).isEncrypted && Provider.of(context, listen: false).onion.isEmpty && value.isEmpty && usePassword) { return AppLocalizations.of(context)!.passwordErrorEmpty; } if (Provider.of(context).deleteProfileError == true) { diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index 0d05070..dfa79f6 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -72,7 +72,7 @@ class _ProfileRowState extends State { tooltip: AppLocalizations.of(context)!.editProfile + " " + profile.nickname, icon: Icon(Icons.create, color: Provider.of(context).current().mainTextColor()), onPressed: () { - _pushAddEditProfile(onion: profile.onion, displayName: profile.nickname, profileImage: profile.imagePath); + _pushAddEditProfile(onion: profile.onion, displayName: profile.nickname, profileImage: profile.imagePath, encrypted: profile.isEncrypted); }, ) ], @@ -113,13 +113,13 @@ class _ProfileRowState extends State { ); } - void _pushAddEditProfile({onion: "", displayName: "", profileImage: ""}) { + void _pushAddEditProfile({onion: "", displayName: "", profileImage: "", encrypted: true}) { Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider( - create: (_) => ProfileInfoState(onion: onion, nickname: displayName, imagePath: profileImage), + create: (_) => ProfileInfoState(onion: onion, nickname: displayName, imagePath: profileImage, encrypted: encrypted), ), ], builder: (context, widget) => AddEditProfileView(), diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 9f8c703..e71a16d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,6 @@ #include "generated_plugin_registrant.h" -#include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) window_size_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "WindowSizePlugin"); - window_size_plugin_register_with_registrar(window_size_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 9e12128..51436ae 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - window_size ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/pubspec.lock b/pubspec.lock index 0a2c434..ec4202b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + ansicolor: + dependency: transitive + description: + name: ansicolor + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" args: dependency: transitive description: @@ -133,6 +140,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + injector: + dependency: transitive + description: + name: injector + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" intl: dependency: transitive description: @@ -161,6 +175,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.0" + msix: + dependency: "direct dev" + description: + name: msix + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" nested: dependency: transitive description: @@ -182,6 +203,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" package_info_plus: dependency: "direct main" description: @@ -390,6 +418,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.1.2" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" sdks: dart: ">=2.13.0 <3.0.0" flutter: ">=1.20.0" diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 9372fc5..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,6 @@ #include "generated_plugin_registrant.h" -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - WindowSizePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("WindowSizePlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 154f238..4d10c25 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - window_size ) set(PLUGIN_BUNDLED_LIBRARIES)