mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +00:00
Add cubit methods to try recover the server
This commit is contained in:
parent
d2553b0d08
commit
df40a09419
|
@ -3,8 +3,8 @@ import 'dart:async';
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
import '../server_installation/server_installation_repository.dart';
|
import '../server_installation/server_installation_repository.dart';
|
||||||
|
@ -252,6 +252,59 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
timer = Timer(delay, work);
|
timer = Timer(delay, work);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void submitDomainForAccessRecovery(String domain) async {
|
||||||
|
var serverDomain = ServerDomain(
|
||||||
|
domainName: domain,
|
||||||
|
provider: DnsProvider.Unknown,
|
||||||
|
zoneId: '',
|
||||||
|
);
|
||||||
|
final recoveryCapabilities =
|
||||||
|
await repository.getRecoveryCapabilities(serverDomain);
|
||||||
|
|
||||||
|
emit(ServerInstallationRecovery(
|
||||||
|
serverDomain: serverDomain,
|
||||||
|
recoveryCapabilities: recoveryCapabilities,
|
||||||
|
currentStep: RecoveryStep.Selecting,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tryToRecover(String token, ServerRecoveryMethods method) async {
|
||||||
|
final dataState = this.state as ServerInstallationRecovery;
|
||||||
|
final serverDomain = dataState.serverDomain;
|
||||||
|
if (serverDomain == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Future<ServerHostingDetails> Function(ServerDomain, String)
|
||||||
|
recoveryFunction;
|
||||||
|
switch (method) {
|
||||||
|
case ServerRecoveryMethods.newDeviceKey:
|
||||||
|
recoveryFunction = repository.authorizeByNewDeviceKey;
|
||||||
|
break;
|
||||||
|
case ServerRecoveryMethods.recoveryKey:
|
||||||
|
recoveryFunction = repository.authorizeByRecoveryKey;
|
||||||
|
break;
|
||||||
|
case ServerRecoveryMethods.oldToken:
|
||||||
|
recoveryFunction = repository.authorizeByApiToken;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw Exception('Unknown recovery method');
|
||||||
|
}
|
||||||
|
final serverDetails = await recoveryFunction(
|
||||||
|
serverDomain,
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
emit(dataState.copyWith(
|
||||||
|
serverDetails: serverDetails,
|
||||||
|
currentStep: RecoveryStep.HetznerToken,
|
||||||
|
));
|
||||||
|
} on ServerAuthorizationException {
|
||||||
|
return;
|
||||||
|
} on IpNotFoundException {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clearAppConfig() {
|
void clearAppConfig() {
|
||||||
closeTimer();
|
closeTimer();
|
||||||
|
|
||||||
|
|
|
@ -371,9 +371,9 @@ class ServerInstallationRepository {
|
||||||
return 'Unidentified';
|
return 'Unidentified';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails> authorizeByLoginToken(
|
Future<ServerHostingDetails> authorizeByNewDeviceKey(
|
||||||
ServerDomain serverDomain,
|
ServerDomain serverDomain,
|
||||||
String loginToken,
|
String newDeviceKey,
|
||||||
) async {
|
) async {
|
||||||
var serverApi = ServerApi(
|
var serverApi = ServerApi(
|
||||||
isWithToken: false,
|
isWithToken: false,
|
||||||
|
@ -381,7 +381,7 @@ class ServerInstallationRepository {
|
||||||
);
|
);
|
||||||
final serverIp = await getServerIpFromDomain(serverDomain);
|
final serverIp = await getServerIpFromDomain(serverDomain);
|
||||||
final apiResponse = await serverApi.authorizeDevice(
|
final apiResponse = await serverApi.authorizeDevice(
|
||||||
DeviceToken(device: await getDeviceName(), token: loginToken));
|
DeviceToken(device: await getDeviceName(), token: newDeviceKey));
|
||||||
|
|
||||||
if (apiResponse.isSuccess) {
|
if (apiResponse.isSuccess) {
|
||||||
return ServerHostingDetails(
|
return ServerHostingDetails(
|
||||||
|
@ -403,16 +403,16 @@ class ServerInstallationRepository {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails> authorizeByRecoveryToken(
|
Future<ServerHostingDetails> authorizeByRecoveryKey(
|
||||||
ServerDomain serverDomain,
|
ServerDomain serverDomain,
|
||||||
String recoveryToken,
|
String recoveryKey,
|
||||||
) async {
|
) async {
|
||||||
var serverApi = ServerApi(
|
var serverApi = ServerApi(
|
||||||
isWithToken: false,
|
isWithToken: false,
|
||||||
overrideDomain: serverDomain.domainName,
|
overrideDomain: serverDomain.domainName,
|
||||||
);
|
);
|
||||||
final apiResponse = await serverApi.useRecoveryToken(
|
final apiResponse = await serverApi.useRecoveryToken(
|
||||||
DeviceToken(device: await getDeviceName(), token: recoveryToken));
|
DeviceToken(device: await getDeviceName(), token: recoveryKey));
|
||||||
|
|
||||||
if (apiResponse.isSuccess) {
|
if (apiResponse.isSuccess) {
|
||||||
return ServerHostingDetails(
|
return ServerHostingDetails(
|
||||||
|
|
|
@ -271,6 +271,12 @@ enum ServerRecoveryCapabilities {
|
||||||
loginTokens,
|
loginTokens,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ServerRecoveryMethods {
|
||||||
|
newDeviceKey,
|
||||||
|
recoveryKey,
|
||||||
|
oldToken,
|
||||||
|
}
|
||||||
|
|
||||||
class ServerInstallationRecovery extends ServerInstallationState {
|
class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
final RecoveryStep currentStep;
|
final RecoveryStep currentStep;
|
||||||
final ServerRecoveryCapabilities recoveryCapabilities;
|
final ServerRecoveryCapabilities recoveryCapabilities;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
part of 'server_details_screen.dart';
|
part of 'server_details.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// TypeAdapterGenerator
|
// TypeAdapterGenerator
|
||||||
|
|
Loading…
Reference in a new issue