mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-08-23 21:41:51 +00:00
Because the class is called ServerApi, not just Server, it's totally not consistent with all other apis
54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
|
|
|
class RecoveryDomainFormCubit extends FormCubit {
|
|
RecoveryDomainFormCubit(
|
|
this.initializingCubit,
|
|
final FieldCubitFactory fieldFactory,
|
|
) {
|
|
serverDomainField = fieldFactory.createRequiredStringField();
|
|
|
|
super.addFields([serverDomainField]);
|
|
}
|
|
|
|
@override
|
|
FutureOr<void> onSubmit() async {
|
|
initializingCubit.submitDomainForAccessRecovery(
|
|
serverDomainField.state.value.toLowerCase(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
FutureOr<bool> asyncValidation() async {
|
|
final ServerApi api = ServerApi(
|
|
hasLogger: false,
|
|
isWithToken: false,
|
|
overrideDomain: serverDomainField.state.value,
|
|
);
|
|
|
|
// API version doesn't require access token,
|
|
// so if the entered domain is indeed valid
|
|
// and the server by it is reachable, we will
|
|
// be able to confirm the input
|
|
|
|
final bool domainValid = await api.getApiVersion() != null;
|
|
if (!domainValid) {
|
|
serverDomainField.setError('recovering.domain_recover_error'.tr());
|
|
}
|
|
|
|
return domainValid;
|
|
}
|
|
|
|
FutureOr<void> setCustomError(final String error) {
|
|
serverDomainField.setError(error);
|
|
}
|
|
|
|
final ServerInstallationCubit initializingCubit;
|
|
late final FieldCubit<String> serverDomainField;
|
|
}
|