mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-29 12:16:55 +00:00
update
This commit is contained in:
parent
cf6e0b3495
commit
853e1fdbdd
|
@ -5,10 +5,10 @@ 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 UserFormCubit extends FormCubit {
|
||||
class RootUserFormCubit extends FormCubit {
|
||||
HetznerApi apiClient = HetznerApi();
|
||||
|
||||
UserFormCubit(this.initializingCubit) {
|
||||
RootUserFormCubit(this.initializingCubit) {
|
||||
var userRegExp = RegExp(r"\W");
|
||||
var passwordRegExp = RegExp(r"[\n\r\s]+");
|
||||
|
|
@ -3,10 +3,11 @@ import 'dart:async';
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/user.dart';
|
||||
import 'package:selfprivacy/utils/password_generator.dart';
|
||||
|
||||
class CloudFlareFormCubit extends FormCubit {
|
||||
CloudFlareFormCubit({
|
||||
this.userCubit,
|
||||
class UserFormCubit extends FormCubit {
|
||||
UserFormCubit({
|
||||
this.usersCubit,
|
||||
User user,
|
||||
}) {
|
||||
var isEdit = user != null;
|
||||
|
@ -24,7 +25,7 @@ class CloudFlareFormCubit extends FormCubit {
|
|||
);
|
||||
|
||||
password = FieldCubit(
|
||||
initalValue: isEdit ? user.password : '',
|
||||
initalValue: isEdit ? user.password : genPass(),
|
||||
validations: [
|
||||
RequiredStringValidation('required'),
|
||||
ValidationModel<String>(
|
||||
|
@ -41,11 +42,15 @@ class CloudFlareFormCubit extends FormCubit {
|
|||
login: login.state.value,
|
||||
password: password.state.value,
|
||||
);
|
||||
userCubit.add(user);
|
||||
usersCubit.add(user);
|
||||
}
|
||||
|
||||
FieldCubit<String> login;
|
||||
FieldCubit<String> password;
|
||||
|
||||
UsersCubit userCubit;
|
||||
void genNewPassword() {
|
||||
password.externalSetValue(genPass());
|
||||
}
|
||||
|
||||
UsersCubit usersCubit;
|
||||
}
|
|
@ -9,14 +9,14 @@ class UsersCubit extends Cubit<UsersState> {
|
|||
UsersCubit() : super(UsersState([]));
|
||||
|
||||
void add(User user) {
|
||||
var users = state.users;
|
||||
var users = [...state.users];
|
||||
users.add(user);
|
||||
|
||||
emit(UsersState(users));
|
||||
}
|
||||
|
||||
void remove(User user) {
|
||||
var users = state.users;
|
||||
var users = [...state.users];
|
||||
users.remove(user);
|
||||
|
||||
emit(UsersState(users));
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:selfprivacy/config/text_themes.dart';
|
|||
import 'package:selfprivacy/logic/cubit/forms/initializing/cloudflare_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/initializing/domain_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/initializing/hetzner_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/initializing/user_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/initializing/root_user_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
@ -217,9 +217,9 @@ class InitializingPage extends StatelessWidget {
|
|||
|
||||
Widget _stepUser(AppConfigCubit initializingCubit) {
|
||||
return BlocProvider(
|
||||
create: (context) => UserFormCubit(initializingCubit),
|
||||
create: (context) => RootUserFormCubit(initializingCubit),
|
||||
child: Builder(builder: (context) {
|
||||
var formCubit = context.watch<UserFormCubit>();
|
||||
var formCubit = context.watch<RootUserFormCubit>();
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
|
|
@ -1,73 +1,76 @@
|
|||
part of 'users.dart';
|
||||
|
||||
class _NewUser extends StatefulWidget {
|
||||
const _NewUser({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
__NewUserState createState() => __NewUserState();
|
||||
}
|
||||
|
||||
class __NewUserState extends State<_NewUser> {
|
||||
var passController = TextEditingController(text: genPass());
|
||||
|
||||
class _NewUser extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final usersCubit = context.watch<UsersCubit>();
|
||||
final usersCubit = context.watch<UsersCubit>();
|
||||
|
||||
return BrandModalSheet(
|
||||
child: Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BrandHeader(title: 'Новый пользователь'),
|
||||
SizedBox(width: 14),
|
||||
Padding(
|
||||
padding: brandPagePadding2,
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Логин',
|
||||
suffixText: '@example',
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: passController,
|
||||
decoration: InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Пароль',
|
||||
suffixIcon: Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
BrandIcons.refresh,
|
||||
color: BrandColors.blue,
|
||||
),
|
||||
onPressed: () {
|
||||
passController.value =
|
||||
TextEditingValue(text: genPass());
|
||||
},
|
||||
child: BlocProvider(
|
||||
create: (context) => UserFormCubit(usersCubit: usersCubit),
|
||||
child: Builder(builder: (context) {
|
||||
var formCubit = context.watch<UserFormCubit>();
|
||||
|
||||
return BlocListener<UserFormCubit, FormCubitState>(
|
||||
listener: (context, state) {
|
||||
if (state.isSubmitted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BrandHeader(title: 'Новый пользователь'),
|
||||
SizedBox(width: 14),
|
||||
Padding(
|
||||
padding: brandPagePadding2,
|
||||
child: Column(
|
||||
children: [
|
||||
CubitFormTextField(
|
||||
formFieldCubit: formCubit.login,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Логин',
|
||||
suffixText: '@example',
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
CubitFormTextField(
|
||||
formFieldCubit: formCubit.password,
|
||||
decoration: InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Пароль',
|
||||
suffixIcon: Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
BrandIcons.refresh,
|
||||
color: BrandColors.blue,
|
||||
),
|
||||
onPressed: formCubit.genNewPassword,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 30),
|
||||
BrandButton.rised(
|
||||
onPressed: formCubit.state.isSubmitting
|
||||
? null
|
||||
: () {
|
||||
formCubit.trySubmit();
|
||||
},
|
||||
title: 'Создать',
|
||||
),
|
||||
SizedBox(height: 40),
|
||||
Text(
|
||||
'Новый пользователь автоматически получит доступ ко всем сервисам. Ещё какое-то описание.'),
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 30),
|
||||
BrandButton.rised(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
title: 'Создать',
|
||||
),
|
||||
SizedBox(height: 40),
|
||||
Text(
|
||||
'Новый пользователь автоматически получит доступ ко всем сервисам. Ещё какое-то описание.'),
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ class _UserDetails extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
onPressed: () {
|
||||
context.read<UsersCubit>().remove(user);
|
||||
Navigator.of(context)..pop()..pop();
|
||||
},
|
||||
),
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/config/brand_colors.dart';
|
||||
import 'package:selfprivacy/config/brand_theme.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/user.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
@ -11,7 +13,6 @@ import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
|||
import 'package:selfprivacy/ui/components/brand_modal_sheet/brand_modal_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
||||
import 'package:selfprivacy/utils/password_generator.dart';
|
||||
|
||||
part 'fab.dart';
|
||||
part 'new_user.dart';
|
||||
|
|
|
@ -182,7 +182,7 @@ packages:
|
|||
name: cubit_form
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.15"
|
||||
version: "0.0.16"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -10,7 +10,7 @@ dependencies:
|
|||
flutter:
|
||||
sdk: flutter
|
||||
crypto: ^2.1.5
|
||||
cubit_form: ^0.0.15
|
||||
cubit_form: ^0.0.16
|
||||
cupertino_icons: ^1.0.0
|
||||
dio: ^3.0.10
|
||||
easy_localization: ^2.3.3
|
||||
|
|
Loading…
Reference in a new issue