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