mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-09-06 20:16:56 +00:00
57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
|
import 'package:selfprivacy/logic/models/user.dart';
|
|
|
|
class RootUserFormCubit extends FormCubit {
|
|
HetznerApi apiClient = HetznerApi();
|
|
|
|
RootUserFormCubit(this.initializingCubit) {
|
|
var userRegExp = RegExp(r"\W");
|
|
var passwordRegExp = RegExp(r"[\n\r\s]+");
|
|
|
|
userName = FieldCubit(
|
|
initalValue: '',
|
|
validations: [
|
|
RequiredStringValidation('required'),
|
|
ValidationModel<String>(
|
|
(s) => userRegExp.hasMatch(s), 'invalid format'),
|
|
],
|
|
);
|
|
|
|
password = FieldCubit(
|
|
initalValue: '',
|
|
validations: [
|
|
RequiredStringValidation('required'),
|
|
ValidationModel<String>(
|
|
(s) => passwordRegExp.hasMatch(s), 'invalid format'),
|
|
],
|
|
);
|
|
|
|
super.setFields([userName, password]);
|
|
}
|
|
|
|
@override
|
|
FutureOr<void> onSubmit() async {
|
|
var user = User(
|
|
login: userName.state.value,
|
|
password: password.state.value,
|
|
);
|
|
initializingCubit.setRootUser(user);
|
|
}
|
|
|
|
final AppConfigCubit initializingCubit;
|
|
|
|
FieldCubit<String> userName;
|
|
FieldCubit<String> password;
|
|
|
|
@override
|
|
Future<void> close() async {
|
|
apiClient.close();
|
|
|
|
return super.close();
|
|
}
|
|
}
|