mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 03:06:41 +00:00
Finish recovery flow cubit
This commit is contained in:
parent
eddeac57d6
commit
fa6f74e884
|
@ -311,7 +311,8 @@
|
|||
"confirm_server_decline": "Choose a different server",
|
||||
"choose_server": "Choose your server",
|
||||
"choose_server_description": "We couldn't figure out which server your are trying to connect to.",
|
||||
"no_servers": "There is no available servers on your account."
|
||||
"no_servers": "There is no available servers on your account.",
|
||||
"domain_not_available_on_token": "Selected domain is not available on this token."
|
||||
|
||||
},
|
||||
"modals": {
|
||||
|
|
|
@ -313,7 +313,9 @@
|
|||
"confirm_server_decline": "Выбрать другой сервер",
|
||||
"choose_server": "Выберите сервер",
|
||||
"choose_server_description": "Не удалось определить, с каким сервером вы устанавливаете связь.",
|
||||
"no_servers": "На вашем аккаунте нет доступных серверов."
|
||||
"no_servers": "На вашем аккаунте нет доступных серверов.",
|
||||
"domain_not_available_on_token": "Введённый токен не имеет доступа к нужному домену."
|
||||
|
||||
},
|
||||
"modals": {
|
||||
"_comment": "messages in modals",
|
||||
|
|
|
@ -153,13 +153,15 @@ class ServerApi extends ApiMap {
|
|||
);
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<String>>> getUsersList() async {
|
||||
Future<ApiResponse<List<String>>> getUsersList(
|
||||
{withMainUser = false}
|
||||
) async {
|
||||
List<String> res = [];
|
||||
Response response;
|
||||
|
||||
var client = await getClient();
|
||||
try {
|
||||
response = await client.get('/users');
|
||||
response = await client.get('/users', queryParameters: withMainUser ? {'withMainUser': 'true'} : null);
|
||||
for (var user in response.data) {
|
||||
res.add(user.toString());
|
||||
}
|
||||
|
|
|
@ -75,6 +75,15 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
applicationKey: applicationKey,
|
||||
);
|
||||
await repository.saveBackblazeKey(backblazeCredential);
|
||||
if (state is ServerInstallationRecovery) {
|
||||
final mainUser = await repository.getMainUser();
|
||||
final updatedState = (state as ServerInstallationRecovery).copyWith(
|
||||
backblazeCredential: backblazeCredential,
|
||||
rootUser: mainUser,
|
||||
);
|
||||
emit(updatedState.finish());
|
||||
return;
|
||||
}
|
||||
emit((state as ServerInstallationNotFinished)
|
||||
.copyWith(backblazeCredential: backblazeCredential));
|
||||
}
|
||||
|
@ -410,14 +419,27 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
));
|
||||
}
|
||||
|
||||
// Future<void> setAndValidateCloudflareToken(String token) async {
|
||||
// final dataState = this.state as ServerInstallationRecovery;
|
||||
// final serverDomain = dataState.serverDomain;
|
||||
// if (serverDomain == null) {
|
||||
// return;
|
||||
// }
|
||||
// final domainId = await repository.getDomainId(serverDomain.domainName);
|
||||
// }
|
||||
Future<void> setAndValidateCloudflareToken(String token) async {
|
||||
final dataState = this.state as ServerInstallationRecovery;
|
||||
final serverDomain = dataState.serverDomain;
|
||||
if (serverDomain == null) {
|
||||
return;
|
||||
}
|
||||
final zoneId = await repository.getDomainId(token, serverDomain.domainName);
|
||||
if (zoneId == null) {
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar('recovering.domain_not_available_on_token'.tr());
|
||||
return;
|
||||
}
|
||||
emit(dataState.copyWith(
|
||||
serverDomain: ServerDomain(
|
||||
domainName: serverDomain.domainName,
|
||||
zoneId: zoneId,
|
||||
provider: DnsProvider.Cloudflare,
|
||||
),
|
||||
currentStep: RecoveryStep.BackblazeToken,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void onChange(Change<ServerInstallationState> change) {
|
||||
|
|
|
@ -346,7 +346,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
try {
|
||||
final parsedVersion = Version.parse(serverApiVersion);
|
||||
if (parsedVersion.major == 1 && parsedVersion.minor < 2) {
|
||||
if (!VersionConstraint.parse('>=1.2.0').allows(parsedVersion)) {
|
||||
return ServerRecoveryCapabilities.legacy;
|
||||
}
|
||||
return ServerRecoveryCapabilities.loginTokens;
|
||||
|
@ -485,6 +485,34 @@ class ServerInstallationRepository {
|
|||
);
|
||||
}
|
||||
|
||||
Future<User> getMainUser() async {
|
||||
var serverApi = ServerApi();
|
||||
final fallbackUser = User(
|
||||
isFoundOnServer: false,
|
||||
note: 'Couldn\'t find main user on server, API is outdated',
|
||||
login: 'UNKNOWN',
|
||||
sshKeys: [],
|
||||
);
|
||||
|
||||
final serverApiVersion = await serverApi.getApiVersion();
|
||||
final users = await serverApi.getUsersList(withMainUser: true);
|
||||
if (serverApiVersion == null || !users.isSuccess) {
|
||||
return fallbackUser;
|
||||
}
|
||||
try {
|
||||
final parsedVersion = Version.parse(serverApiVersion);
|
||||
if (!VersionConstraint.parse('>=1.2.5').allows(parsedVersion)) {
|
||||
return fallbackUser;
|
||||
}
|
||||
return User(
|
||||
isFoundOnServer: true,
|
||||
login: users.data[0],
|
||||
);
|
||||
} on FormatException {
|
||||
return fallbackUser;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ServerBasicInfo>> getServersOnHetznerAccount() async {
|
||||
var hetznerApi = HetznerApi();
|
||||
final servers = await hetznerApi.getServers();
|
||||
|
|
|
@ -336,4 +336,18 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
currentStep: currentStep ?? this.currentStep,
|
||||
recoveryCapabilities: recoveryCapabilities ?? this.recoveryCapabilities,
|
||||
);
|
||||
|
||||
ServerInstallationFinished finish() {
|
||||
return ServerInstallationFinished(
|
||||
hetznerKey: hetznerKey!,
|
||||
cloudFlareKey: cloudFlareKey!,
|
||||
backblazeCredential: backblazeCredential!,
|
||||
serverDomain: serverDomain!,
|
||||
rootUser: rootUser!,
|
||||
serverDetails: serverDetails!,
|
||||
isServerStarted: true,
|
||||
isServerResetedFirstTime: true,
|
||||
isServerResetedSecondTime: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue