Merge pull request 'naiji-dev' (#91) from naiji-dev into develop

Reviewed-on: kherel/selfprivacy.org.app#91
pull/97/head
Inex Code 2022-06-23 12:12:37 +03:00
commit c4f62e012b
14 changed files with 60 additions and 17 deletions

View File

@ -259,6 +259,9 @@
"1": "Connect a server",
"2": "A place where your data and SelfPrivacy services will reside:",
"how": "How to obtain API token",
"hetzner_bad_key_error": "Hetzner API key is invalid",
"cloudflare_bad_key_error": "Cloudflare API key is invalid",
"backblaze_bad_key_error": "Backblaze storage information is invalid",
"3": "Connect CloudFlare",
"4": "To manage your domain's DNS",
"5": "CloudFlare API Token",

View File

@ -260,6 +260,9 @@
"1": "Подключите сервер",
"2": "Здесь будут жить наши данные и SelfPrivacy-сервисы",
"how": "Как получить API Token",
"hetzner_bad_key_error": "Hetzner API ключ неверен",
"cloudflare_bad_key_error": "Cloudflare API ключ неверен",
"backblaze_bad_key_error": "Информация о Backblaze хранилище неверна",
"3": "Подключите CloudFlare",
"4": "Для управления DNS вашего домена",
"5": "CloudFlare API Token",

View File

@ -0,0 +1,3 @@
- Fixed routing errors and broken "back" buttons on recovery stages
- Fixed broken validation on api token fields
- Minor improvements

View File

@ -55,10 +55,11 @@ class BackblazeFormCubit extends FormCubit {
}
if (!isKeyValid) {
keyId.setError('bad key');
applicationKey.setError('bad key');
keyId.setError('initializing.backblaze_bad_key_error'.tr());
applicationKey.setError('initializing.backblaze_bad_key_error'.tr());
return false;
}
return true;
}
}

View File

@ -42,12 +42,14 @@ class CloudFlareFormCubit extends FormCubit {
isKeyValid = await apiClient.isValid(apiKey.state.value);
} catch (e) {
addError(e);
isKeyValid = false;
}
if (!isKeyValid) {
apiKey.setError('bad key');
apiKey.setError('initializing.cloudflare_bad_key_error'.tr());
return false;
}
return true;
}
}

View File

@ -42,12 +42,14 @@ class HetznerFormCubit extends FormCubit {
isKeyValid = await apiClient.isValid(apiKey.state.value);
} catch (e) {
addError(e);
isKeyValid = false;
}
if (!isKeyValid) {
apiKey.setError('bad key');
apiKey.setError('initializing.hetzner_bad_key_error'.tr());
return false;
}
return true;
}
}

View File

@ -417,11 +417,11 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
),
);
break;
case RecoveryStep.serverSelection:
repository.deleteHetznerKey();
case RecoveryStep.cloudflareToken:
repository.deleteServerDetails();
emit(
dataState.copyWith(
currentStep: RecoveryStep.hetznerToken,
currentStep: RecoveryStep.serverSelection,
),
);
break;

View File

@ -242,13 +242,18 @@ class ServerInstallationRepository {
domainName: domainName,
);
final ServerHostingDetails? serverDetails =
await hetznerApi.createServer(
cloudFlareKey: cloudFlareKey,
rootUser: rootUser,
domainName: domainName,
dataBase: dataBase,
);
ServerHostingDetails? serverDetails;
try {
serverDetails = await hetznerApi.createServer(
cloudFlareKey: cloudFlareKey,
rootUser: rootUser,
domainName: domainName,
dataBase: dataBase,
);
} catch (e) {
print(e);
}
if (serverDetails == null) {
print('Server is not initialized!');
return;
@ -598,6 +603,11 @@ class ServerInstallationRepository {
await getIt<ApiConfigModel>().storeServerDetails(serverDetails);
}
Future<void> deleteServerDetails() async {
await box.delete(BNames.serverDetails);
getIt<ApiConfigModel>().init();
}
Future<void> saveHetznerKey(final String key) async {
print('saved');
await getIt<ApiConfigModel>().storeHetznerKey(key);
@ -614,10 +624,20 @@ class ServerInstallationRepository {
await getIt<ApiConfigModel>().storeBackblazeCredential(backblazeCredential);
}
Future<void> deleteBackblazeKey() async {
await box.delete(BNames.backblazeCredential);
getIt<ApiConfigModel>().init();
}
Future<void> saveCloudFlareKey(final String key) async {
await getIt<ApiConfigModel>().storeCloudFlareKey(key);
}
Future<void> deleteCloudFlareKey() async {
await box.delete(BNames.cloudFlareKey);
getIt<ApiConfigModel>().init();
}
Future<void> saveDomain(final ServerDomain serverDomain) async {
await getIt<ApiConfigModel>().storeServerDomain(serverDomain);
}

View File

@ -34,7 +34,6 @@ class ApiConfigModel {
Future<void> storeBackblazeCredential(final BackblazeCredential value) async {
await _box.put(BNames.backblazeCredential, value);
_backblazeCredential = value;
}
@ -64,7 +63,6 @@ class ApiConfigModel {
void init() {
_hetznerKey = _box.get(BNames.hetznerKey);
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
_backblazeCredential = _box.get(BNames.backblazeCredential);
_serverDomain = _box.get(BNames.serverDomain);

View File

@ -28,6 +28,9 @@ class RecoveryConfirmBackblaze extends StatelessWidget {
heroTitle: 'recovering.confirm_backblaze'.tr(),
heroSubtitle: 'recovering.confirm_backblaze_description'.tr(),
hasBackButton: true,
onBackButtonPressed: () {
Navigator.of(context).popUntil((final route) => route.isFirst);
},
hasFlashButton: false,
children: [
CubitFormTextField(

View File

@ -31,6 +31,8 @@ class RecoveryConfirmCloudflare extends StatelessWidget {
),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed:
context.read<ServerInstallationCubit>().revertRecoveryStep,
children: [
CubitFormTextField(
formFieldCubit: context.read<CloudFlareFormCubit>().apiKey,

View File

@ -39,6 +39,9 @@ class _RecoveryConfirmServerState extends State<RecoveryConfirmServer> {
? 'recovering.choose_server_description'.tr()
: 'recovering.confirm_server_description'.tr(),
hasBackButton: true,
onBackButtonPressed: () {
Navigator.of(context).popUntil((final route) => route.isFirst);
},
hasFlashButton: false,
children: [
FutureBuilder<List<ServerBasicInfoWithValidators>>(

View File

@ -32,6 +32,9 @@ class RecoveryHetznerConnected extends StatelessWidget {
),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed: () {
Navigator.of(context).popUntil((final route) => route.isFirst);
},
children: [
CubitFormTextField(
formFieldCubit: context.read<HetznerFormCubit>().apiKey,

View File

@ -1,7 +1,7 @@
name: selfprivacy
description: selfprivacy.org
publish_to: 'none'
version: 0.6.0+15
version: 0.6.1+15
environment:
sdk: '>=2.17.0 <3.0.0'