mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-08-21 20:41:50 +00:00
36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
|
|
|
class RecoveryDeviceFormCubit extends FormCubit {
|
|
RecoveryDeviceFormCubit(
|
|
this.installationCubit,
|
|
final FieldCubitFactory fieldFactory,
|
|
this.recoveryMethod,
|
|
) {
|
|
tokenField = fieldFactory.createRequiredStringField();
|
|
|
|
super.addFields([tokenField]);
|
|
}
|
|
|
|
@override
|
|
FutureOr<void> onSubmit() async {
|
|
late final String token;
|
|
// Trim spaces and make lowercase
|
|
if (recoveryMethod == ServerRecoveryMethods.recoveryKey ||
|
|
recoveryMethod == ServerRecoveryMethods.newDeviceKey) {
|
|
token = tokenField.state.value.trim().toLowerCase();
|
|
} else {
|
|
token = tokenField.state.value.trim();
|
|
}
|
|
|
|
installationCubit.tryToRecover(token, recoveryMethod);
|
|
}
|
|
|
|
final ServerInstallationCubit installationCubit;
|
|
late final FieldCubit<String> tokenField;
|
|
final ServerRecoveryMethods recoveryMethod;
|
|
}
|