diff --git a/assets/translations/en.json b/assets/translations/en.json index 22a6b0ee..78ba00c5 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -285,8 +285,9 @@ }, "recovering": { "recovery_main_header": "Connect to an existing server", - "domain_recovery_description": "Enter a server domain you want to get access for", + "domain_recovery_description": "Enter a server domain you want to get access for:", "domain_recover_placeholder": "Your domain", + "domain_recover_error": "Server with such domain is not found", "method_select_description": "Select a recovery method:", "method_select_other_device": "I have access on another device", "method_select_recovery_key": "I have a recovery key", diff --git a/assets/translations/ru.json b/assets/translations/ru.json index 8c1a8397..6a898516 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -288,6 +288,7 @@ "recovery_main_header": "Подключиться к существующему серверу", "domain_recovery_description": "Введите домен, по которому вы хотите получить доступ к серверу:", "domain_recover_placeholder": "Домен", + "domain_recover_error": "Не удалось найти сервер с таким доменом", "method_select_description": "Выберите способ входа:", "method_select_other_device": "У меня есть доступ на другом устройстве", "method_select_recovery_key": "У меня есть ключ восстановления", diff --git a/lib/logic/cubit/forms/setup/recovering/recovery_domain_form_cubit.dart b/lib/logic/cubit/forms/setup/recovering/recovery_domain_form_cubit.dart index d9d494ff..59e512d2 100644 --- a/lib/logic/cubit/forms/setup/recovering/recovery_domain_form_cubit.dart +++ b/lib/logic/cubit/forms/setup/recovering/recovery_domain_form_cubit.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:cubit_form/cubit_form.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:selfprivacy/logic/api_maps/server.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart'; @@ -22,10 +23,25 @@ class RecoveryDomainFormCubit extends FormCubit { zoneId: "")); } - // @override - // FutureOr asyncValidation() async { - // ; //var client = - // } + @override + FutureOr asyncValidation() async { + var 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; + } final ServerInstallationCubit initializingCubit; late final FieldCubit serverDomainField; diff --git a/lib/ui/pages/setup/initializing.dart b/lib/ui/pages/setup/initializing.dart index 627f4014..8e6fd1ec 100644 --- a/lib/ui/pages/setup/initializing.dart +++ b/lib/ui/pages/setup/initializing.dart @@ -17,7 +17,7 @@ import 'package:selfprivacy/ui/components/brand_text/brand_text.dart'; import 'package:selfprivacy/ui/components/brand_timer/brand_timer.dart'; import 'package:selfprivacy/ui/components/progress_bar/progress_bar.dart'; import 'package:selfprivacy/ui/pages/rootRoute.dart'; -import 'package:selfprivacy/ui/pages/setup/recovering/recovery_method_select.dart'; +import 'package:selfprivacy/ui/pages/setup/recovering/recovery_domain.dart'; import 'package:selfprivacy/utils/route_transitions/basic.dart'; class InitializingPage extends StatelessWidget { @@ -104,8 +104,8 @@ class InitializingPage extends StatelessWidget { child: BrandButton.text( title: 'basis.connect_to_existing'.tr(), onPressed: () { - Navigator.of(context).push( - materialRoute(RecoveryMethodSelect())); + Navigator.of(context) + .push(materialRoute(RecoveryDomain())); }, ), )