diff --git a/packages/neon_framework/lib/src/blocs/push_notifications.dart b/packages/neon_framework/lib/src/blocs/push_notifications.dart index 3b6967e2e72..111b36cd829 100644 --- a/packages/neon_framework/lib/src/blocs/push_notifications.dart +++ b/packages/neon_framework/lib/src/blocs/push_notifications.dart @@ -136,7 +136,7 @@ class _PushNotificationsBloc extends Bloc implements PushNotificationsBloc { Future registerUnifiedPushInstances(({Account? active, BuiltList accounts}) event) async { // Notifications will only work on accounts with app password - for (final account in event.accounts.where((a) => a.password != null)) { + for (final account in event.accounts.where((a) => a.credentials.appPassword != null)) { await UnifiedPush.registerApp(account.id); } } diff --git a/packages/neon_framework/lib/src/testing/mock_server.dart b/packages/neon_framework/lib/src/testing/mock_server.dart index 5a0563ba71a..e3b60d83b27 100644 --- a/packages/neon_framework/lib/src/testing/mock_server.dart +++ b/packages/neon_framework/lib/src/testing/mock_server.dart @@ -29,7 +29,7 @@ Account mockServer( credentials: createCredentials( serverURL: Uri.parse('https://example.com'), username: 'test', - password: 'test', + appPassword: 'test', ), httpClient: client, ); diff --git a/packages/neon_framework/lib/src/testing/mocks.dart b/packages/neon_framework/lib/src/testing/mocks.dart index 131fbd0269e..2eddde03590 100644 --- a/packages/neon_framework/lib/src/testing/mocks.dart +++ b/packages/neon_framework/lib/src/testing/mocks.dart @@ -29,13 +29,13 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface. Account MockAccount({ String serverURL = 'https://cloud.example.com:8443/nextcloud', String username = 'username', - String password = 'password', + String appPassword = 'appPassword', }) { return createAccount( credentials: createCredentials( serverURL: Uri.parse(serverURL), username: username, - password: password, + appPassword: appPassword, ), httpClient: MockClient((_) async { throw ClientException('The fake account client can not be used in tests.'); diff --git a/packages/neon_framework/lib/src/utils/account_client_extension.dart b/packages/neon_framework/lib/src/utils/account_client_extension.dart index ef8097306a4..603f1951609 100644 --- a/packages/neon_framework/lib/src/utils/account_client_extension.dart +++ b/packages/neon_framework/lib/src/utils/account_client_extension.dart @@ -12,9 +12,9 @@ extension AccountClientExtension on Account { /// In that case an instance hosted at a sub folder will already contain the sub folder part in the [uri]. @internal Uri completeUri(Uri uri) { - final result = serverURL.resolveUri(uri); + final result = credentials.serverURL.resolveUri(uri); if (!uri.hasAbsolutePath) { - return result.replace(path: '${serverURL.path}/${uri.path}'); + return result.replace(path: '${credentials.serverURL.path}/${uri.path}'); } return result; } @@ -23,7 +23,7 @@ extension AccountClientExtension on Account { /// /// This method ensures no credentials are sent to the wrong server. Map? getAuthorizationHeaders(Uri uri) { - if (uri.toString().startsWith(serverURL.toString())) { + if (uri.toString().startsWith(credentials.serverURL.toString())) { return client.authentications?.firstOrNull?.headers; } diff --git a/packages/neon_framework/lib/src/widgets/error.dart b/packages/neon_framework/lib/src/widgets/error.dart index e8dc1fc2ec1..c424a7f3eb8 100644 --- a/packages/neon_framework/lib/src/widgets/error.dart +++ b/packages/neon_framework/lib/src/widgets/error.dart @@ -155,7 +155,7 @@ class NeonError extends StatelessWidget { static Future _openLoginPage(BuildContext context) async { await LoginRoute( - serverUrl: NeonProvider.of(context).serverURL, + serverUrl: NeonProvider.of(context).credentials.serverURL, ).push(context); } } diff --git a/packages/neon_framework/packages/account_repository/lib/src/account_repository.dart b/packages/neon_framework/packages/account_repository/lib/src/account_repository.dart index 1690ba6ba54..a8bdc465372 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/account_repository.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/account_repository.dart @@ -219,7 +219,7 @@ class AccountRepository { b ..serverURL = Uri.parse(response.server) ..username = response.loginName - ..password = response.appPassword; + ..appPassword = response.appPassword; }); } on http.ClientException catch (error, stackTrace) { if (error case DynamiteStatusCodeException(statusCode: 404)) { diff --git a/packages/neon_framework/packages/account_repository/lib/src/models/account.dart b/packages/neon_framework/packages/account_repository/lib/src/models/account.dart index 25faa3703d8..7a63df107ae 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/models/account.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/models/account.dart @@ -13,21 +13,15 @@ abstract class Account implements Built { /// The login and server credentials of the account. Credentials get credentials; - /// Url of the server. - Uri get serverURL => credentials.serverURL; - /// The user id. String get username => credentials.username; - /// App password. - String? get password => credentials.password; - /// The unique ID of the account. /// - /// Implemented in a primitive way hashing the [username] and [serverURL]. + /// Implemented in a primitive way hashing the [username] and `serverURL`. String get id => credentials.id; - /// A human readable representation of [username] and [serverURL]. + /// A human readable representation of [username] and `serverURL`. String get humanReadableID => credentials.humanReadableID; /// An authenticated API client. diff --git a/packages/neon_framework/packages/account_repository/lib/src/models/credentials.dart b/packages/neon_framework/packages/account_repository/lib/src/models/credentials.dart index 4210826c7c1..3654785df00 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/models/credentials.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/models/credentials.dart @@ -33,7 +33,7 @@ abstract class Credentials implements Built { String get username; /// App password. - String? get password; + String? get appPassword; /// The unique ID of the account. /// diff --git a/packages/neon_framework/packages/account_repository/lib/src/models/credentials.g.dart b/packages/neon_framework/packages/account_repository/lib/src/models/credentials.g.dart index 311c9b6c90e..1a6f91770a8 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/models/credentials.g.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/models/credentials.g.dart @@ -24,10 +24,10 @@ class _$CredentialsSerializer implements StructuredSerializer { serializers.serialize(object.username, specifiedType: const FullType(String)), ]; Object? value; - value = object.password; + value = object.appPassword; if (value != null) { result - ..add('password') + ..add('appPassword') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } return result; @@ -50,8 +50,8 @@ class _$CredentialsSerializer implements StructuredSerializer { case 'username': result.username = serializers.deserialize(value, specifiedType: const FullType(String))! as String; break; - case 'password': - result.password = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + case 'appPassword': + result.appPassword = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; } } @@ -66,14 +66,14 @@ class _$Credentials extends Credentials { @override final String username; @override - final String? password; + final String? appPassword; String? __id; String? __humanReadableID; factory _$Credentials([void Function(CredentialsBuilder)? updates]) => (CredentialsBuilder()..update(updates))._build(); - _$Credentials._({required this.serverURL, required this.username, this.password}) : super._() { + _$Credentials._({required this.serverURL, required this.username, this.appPassword}) : super._() { BuiltValueNullFieldError.checkNotNull(serverURL, r'Credentials', 'serverURL'); BuiltValueNullFieldError.checkNotNull(username, r'Credentials', 'username'); } @@ -96,7 +96,7 @@ class _$Credentials extends Credentials { return other is Credentials && serverURL == other.serverURL && username == other.username && - password == other.password; + appPassword == other.appPassword; } @override @@ -104,7 +104,7 @@ class _$Credentials extends Credentials { var _$hash = 0; _$hash = $jc(_$hash, serverURL.hashCode); _$hash = $jc(_$hash, username.hashCode); - _$hash = $jc(_$hash, password.hashCode); + _$hash = $jc(_$hash, appPassword.hashCode); _$hash = $jf(_$hash); return _$hash; } @@ -114,7 +114,7 @@ class _$Credentials extends Credentials { return (newBuiltValueToStringHelper(r'Credentials') ..add('serverURL', serverURL) ..add('username', username) - ..add('password', password)) + ..add('appPassword', appPassword)) .toString(); } } @@ -130,9 +130,9 @@ class CredentialsBuilder implements Builder { String? get username => _$this._username; set username(String? username) => _$this._username = username; - String? _password; - String? get password => _$this._password; - set password(String? password) => _$this._password = password; + String? _appPassword; + String? get appPassword => _$this._appPassword; + set appPassword(String? appPassword) => _$this._appPassword = appPassword; CredentialsBuilder(); @@ -141,7 +141,7 @@ class CredentialsBuilder implements Builder { if ($v != null) { _serverURL = $v.serverURL; _username = $v.username; - _password = $v.password; + _appPassword = $v.appPassword; _$v = null; } return this; @@ -166,7 +166,7 @@ class CredentialsBuilder implements Builder { _$Credentials._( serverURL: BuiltValueNullFieldError.checkNotNull(serverURL, r'Credentials', 'serverURL'), username: BuiltValueNullFieldError.checkNotNull(username, r'Credentials', 'username'), - password: password); + appPassword: appPassword); replace(_$result); return _$result; } diff --git a/packages/neon_framework/packages/account_repository/lib/src/models/login_qr_code.dart b/packages/neon_framework/packages/account_repository/lib/src/models/login_qr_code.dart index e3cbcf1d8d0..012988fbd76 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/models/login_qr_code.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/models/login_qr_code.dart @@ -57,7 +57,7 @@ final class LoginQRcode with EquatableMixin { b ..serverURL = Uri.parse(match.group(3)!) ..username = match.group(1) - ..password = match.group(2); + ..appPassword = match.group(2); }), ); } @@ -91,7 +91,7 @@ final class LoginQRcode with EquatableMixin { @override String toString() { final username = credentials.username; - final password = credentials.password; + final password = credentials.appPassword; final serverURL = credentials.serverURL; return 'nc://login/user:$username&password:$password&server:$serverURL'; diff --git a/packages/neon_framework/packages/account_repository/lib/src/testing/testing_credentials.dart b/packages/neon_framework/packages/account_repository/lib/src/testing/testing_credentials.dart index ae77a64c224..f7c80cee476 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/testing/testing_credentials.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/testing/testing_credentials.dart @@ -6,12 +6,12 @@ import 'package:meta/meta.dart'; Credentials createCredentials({ Uri? serverURL, String username = 'username', - String? password = 'password', + String? appPassword = 'appPassword', }) { return Credentials((b) { b ..serverURL = serverURL ?? Uri.https('serverURL') ..username = username - ..password = password; + ..appPassword = appPassword; }); } diff --git a/packages/neon_framework/packages/account_repository/lib/src/utils/http_client_builder.dart b/packages/neon_framework/packages/account_repository/lib/src/utils/http_client_builder.dart index 4098991eec0..e40c0f5bb23 100644 --- a/packages/neon_framework/packages/account_repository/lib/src/utils/http_client_builder.dart +++ b/packages/neon_framework/packages/account_repository/lib/src/utils/http_client_builder.dart @@ -26,8 +26,8 @@ NextcloudClient buildClient({ return NextcloudClient( credentials.serverURL, loginName: credentials.username, - password: credentials.password, - appPassword: credentials.password, + password: credentials.appPassword, + appPassword: credentials.appPassword, httpClient: neonHttpClient, ); } diff --git a/packages/neon_framework/packages/account_repository/test/account_repository_test.dart b/packages/neon_framework/packages/account_repository/test/account_repository_test.dart index e86167371f8..3a2c0c0a647 100644 --- a/packages/neon_framework/packages/account_repository/test/account_repository_test.dart +++ b/packages/neon_framework/packages/account_repository/test/account_repository_test.dart @@ -84,13 +84,13 @@ void main() { b ..serverURL = Uri.https('serverUrl') ..username = 'username' - ..password = 'password'; + ..appPassword = 'appPassword'; }), Credentials((b) { b ..serverURL = Uri.https('other-serverUrl') ..username = 'username' - ..password = 'password'; + ..appPassword = 'appPassword'; }), ]); @@ -376,7 +376,7 @@ void main() { equalsBuilt( Credentials((b) { b - ..password = 'appPassword' + ..appPassword = 'appPassword' ..username = 'loginName' ..serverURL = Uri.https('server'); }), diff --git a/packages/neon_framework/packages/account_repository/test/account_storage_test.dart b/packages/neon_framework/packages/account_repository/test/account_storage_test.dart index aadb6ade178..91201c2ab68 100644 --- a/packages/neon_framework/packages/account_repository/test/account_storage_test.dart +++ b/packages/neon_framework/packages/account_repository/test/account_storage_test.dart @@ -31,19 +31,19 @@ void main() { b ..serverURL = Uri.https('serverUrl') ..username = 'username' - ..password = 'password'; + ..appPassword = 'appPassword'; }), Credentials((b) { b ..serverURL = Uri.https('other-serverUrl') ..username = 'username' - ..password = 'password'; + ..appPassword = 'appPassword'; }), ]; final serializedCredentials = BuiltList([ - '{"serverURL":"https://serverurl","username":"username","password":"password"}', - '{"serverURL":"https://other-serverurl","username":"username","password":"password"}', + '{"serverURL":"https://serverurl","username":"username","appPassword":"appPassword"}', + '{"serverURL":"https://other-serverurl","username":"username","appPassword":"appPassword"}', ]); group('AccountStorage', () { diff --git a/packages/neon_framework/packages/account_repository/test/models/account_test.dart b/packages/neon_framework/packages/account_repository/test/models/account_test.dart index a43e02f2775..cdccae51358 100644 --- a/packages/neon_framework/packages/account_repository/test/models/account_test.dart +++ b/packages/neon_framework/packages/account_repository/test/models/account_test.dart @@ -28,7 +28,7 @@ void main() { isNot( equals( createAccount( - credentials: createCredentials(password: null), + credentials: createCredentials(appPassword: null), ), ), ), @@ -49,14 +49,14 @@ void main() { b.credentials ..serverURL = Uri.https('new-serverURL') ..username = 'new-username' - ..password = 'new-password'; + ..appPassword = 'new-appPassword'; }), equals( createAccount( credentials: createCredentials( serverURL: Uri.https('new-serverURL'), username: 'new-username', - password: 'new-password', + appPassword: 'new-appPassword', ), ), ), @@ -69,9 +69,7 @@ void main() { credentials: createCredentials(serverURL: Uri(host: 'server')), ); - expect(account.serverURL, equals(Uri(host: 'server'))); expect(account.username, equals('username')); - expect(account.password, equals('password')); expect(account.id, equals('43c2c7ec8332735e75756dcb08c4fcc6c2b07071')); expect(account.humanReadableID, equals('username@server')); }); @@ -84,7 +82,7 @@ Account { credentials=Credentials { serverURL=https://serverurl, username=username, - password=password, + appPassword=appPassword, }, client=Instance of 'NextcloudClient', }'''), diff --git a/packages/neon_framework/packages/account_repository/test/models/credentials_test.dart b/packages/neon_framework/packages/account_repository/test/models/credentials_test.dart index 1ec04cb11c3..46cdbd992c2 100644 --- a/packages/neon_framework/packages/account_repository/test/models/credentials_test.dart +++ b/packages/neon_framework/packages/account_repository/test/models/credentials_test.dart @@ -27,7 +27,7 @@ void main() { expect( createCredentials(), - isNot(equalsBuilt(createCredentials(password: null))), + isNot(equalsBuilt(createCredentials(appPassword: null))), ); }); @@ -45,13 +45,13 @@ void main() { b ..serverURL = Uri.https('new-serverURL') ..username = 'new-username' - ..password = 'new-password'; + ..appPassword = 'new-appPassword'; }), equalsBuilt( createCredentials( serverURL: Uri.https('new-serverURL'), username: 'new-username', - password: 'new-password', + appPassword: 'new-appPassword', ), ), ); @@ -79,7 +79,7 @@ void main() { final credentialsWithDefaultPort = createCredentials( serverURL: Uri(scheme: 'http', host: 'example.com', port: 80), username: 'JohnDoe', - password: 'super_secret', + appPassword: 'super_secret', ); expect(credentialsWithDefaultPort.humanReadableID, 'JohnDoe@example.com'); @@ -87,7 +87,7 @@ void main() { final credentialsWithPort = createCredentials( serverURL: Uri(scheme: 'http', host: 'example.com', port: 8080), username: 'JohnDoe', - password: 'super_secret', + appPassword: 'super_secret', ); expect(credentialsWithPort.humanReadableID, 'JohnDoe@example.com:8080'); @@ -99,7 +99,7 @@ void main() { Credentials.fromJson({ 'serverURL': 'https://serverurl', 'username': 'username', - 'password': 'password', + 'appPassword': 'appPassword', }), equalsBuilt(createCredentials()), ); @@ -111,7 +111,7 @@ void main() { equals({ 'serverURL': 'https://serverurl', 'username': 'username', - 'password': 'password', + 'appPassword': 'appPassword', }), ); }); @@ -124,7 +124,7 @@ void main() { Credentials { serverURL=https://serverurl, username=username, - password=password, + appPassword=appPassword, }'''), ); }); diff --git a/packages/neon_framework/packages/account_repository/test/models/login_qr_code_test.dart b/packages/neon_framework/packages/account_repository/test/models/login_qr_code_test.dart index da3d3e39842..45b09026e95 100644 --- a/packages/neon_framework/packages/account_repository/test/models/login_qr_code_test.dart +++ b/packages/neon_framework/packages/account_repository/test/models/login_qr_code_test.dart @@ -11,7 +11,7 @@ void main() { b ..serverURL = Uri.parse('example.com') ..username = 'JohnDoe' - ..password = 'super_secret'; + ..appPassword = 'super_secret'; }), ); diff --git a/packages/neon_framework/packages/account_repository/test/utils/http_client_builder_test.dart b/packages/neon_framework/packages/account_repository/test/utils/http_client_builder_test.dart index 11e40ed192b..80104f97edc 100644 --- a/packages/neon_framework/packages/account_repository/test/utils/http_client_builder_test.dart +++ b/packages/neon_framework/packages/account_repository/test/utils/http_client_builder_test.dart @@ -36,7 +36,7 @@ void main() { final credentials = Credentials((b) { b ..username = 'username' - ..password = 'password' + ..appPassword = 'appPassword' ..serverURL = Uri.https('serverURL'); }); diff --git a/packages/neon_framework/packages/talk_app/lib/src/widgets/rich_object/file.dart b/packages/neon_framework/packages/talk_app/lib/src/widgets/rich_object/file.dart index 4c524062224..d0f9e48d9bb 100644 --- a/packages/neon_framework/packages/talk_app/lib/src/widgets/rich_object/file.dart +++ b/packages/neon_framework/packages/talk_app/lib/src/widgets/rich_object/file.dart @@ -60,7 +60,9 @@ class TalkRichObjectFile extends StatelessWidget { // Previews for animated GIFs are not animated, so we have to request the full file. image = NeonUriImage( account: account, - uri: Uri.parse('${account.serverURL}/remote.php/dav/files/${account.username}/${parameter.path!}'), + uri: Uri.parse( + '${account.credentials.serverURL}/remote.php/dav/files/${account.username}/${parameter.path!}', + ), ); } else { image = NeonApiImage( diff --git a/packages/neon_framework/test/login/bloc/login_bloc_test.dart b/packages/neon_framework/test/login/bloc/login_bloc_test.dart index f17e5a074e8..8eab832832f 100644 --- a/packages/neon_framework/test/login/bloc/login_bloc_test.dart +++ b/packages/neon_framework/test/login/bloc/login_bloc_test.dart @@ -24,7 +24,6 @@ void main() { }); final serverURL = Uri.https('serverURL'); - final credentials = createCredentials( serverURL: Uri.https('credentials_serverURL'), ); diff --git a/packages/neon_framework/test/login/bloc/login_state_test.dart b/packages/neon_framework/test/login/bloc/login_state_test.dart index 16d4c25017a..d791e989cb9 100644 --- a/packages/neon_framework/test/login/bloc/login_state_test.dart +++ b/packages/neon_framework/test/login/bloc/login_state_test.dart @@ -6,7 +6,6 @@ import 'package:neon_framework/src/login/login.dart'; void main() { final url = Uri.https('serverURL'); - final credentials = createCredentials( serverURL: Uri.https('credentials_serverURL'), ); diff --git a/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_bloc_test.dart b/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_bloc_test.dart index 4f2fca01625..281f5c94f34 100644 --- a/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_bloc_test.dart +++ b/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_bloc_test.dart @@ -37,7 +37,7 @@ void main() { b ..serverURL = Uri.https('example.com') ..username = 'JohnDoe' - ..password = 'super_secret'; + ..appPassword = 'super_secret'; }), ), ], diff --git a/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_state_test.dart b/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_state_test.dart index 84b85f7415d..1f785e0b043 100644 --- a/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_state_test.dart +++ b/packages/neon_framework/test/login_qr_code/bloc/login_qr_code_state_test.dart @@ -60,7 +60,7 @@ void main() { credentials: createCredentials( serverURL: Uri.https('new-serverURL'), username: 'new-username', - password: 'new-password', + appPassword: 'new-appPassword', ), invalid: true, ), @@ -69,7 +69,7 @@ void main() { credentials: createCredentials( serverURL: Uri.https('new-serverURL'), username: 'new-username', - password: 'new-password', + appPassword: 'new-appPassword', ), invalid: true, ), diff --git a/packages/neon_framework/test/utils/account_client_extension_test.dart b/packages/neon_framework/test/utils/account_client_extension_test.dart index 72f17fcbaa2..eca5aee9bef 100644 --- a/packages/neon_framework/test/utils/account_client_extension_test.dart +++ b/packages/neon_framework/test/utils/account_client_extension_test.dart @@ -17,7 +17,7 @@ void main() { credentials: createCredentials( serverURL: Uri.parse(serverURL), username: 'example', - password: null, + appPassword: null, ), ); @@ -43,7 +43,7 @@ void main() { credentials: createCredentials( serverURL: Uri.parse('https://example.com:443/test'), username: 'example', - password: 'example', + appPassword: 'example', ), );