mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-30 04:21:45 +00:00

* feat: implement encrypt and decrypt * feat: encrypt and decrypt * feat: update user profile with encrypt * chore: store encryption sign * fix: login in setting menu * chore: show encryption account name * chore: fix test * ci: fix warnings * test: enable supabase test * chore: fix test and rename column * fix: update user profile after set the secret * fix: encryption with wrong secret * fix: don't save user data if the return value of did_sign_up is err * chore: encrypt snapshot data * chore: refactor snapshots interface * ci: add tests * chore: update collab rev
125 lines
4.7 KiB
Dart
125 lines
4.7 KiB
Dart
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
import 'package:appflowy/startup/startup.dart';
|
|
import 'package:appflowy/workspace/presentation/home/toast.dart';
|
|
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
|
|
import 'package:appflowy_backend/log.dart';
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import '../application/encrypt_secret_bloc.dart';
|
|
|
|
class EncryptSecretScreen extends StatefulWidget {
|
|
final UserProfilePB user;
|
|
const EncryptSecretScreen({required this.user, super.key});
|
|
|
|
@override
|
|
State<EncryptSecretScreen> createState() => _EncryptSecretScreenState();
|
|
}
|
|
|
|
class _EncryptSecretScreenState extends State<EncryptSecretScreen> {
|
|
final TextEditingController _textEditingController = TextEditingController();
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: BlocProvider(
|
|
create: (context) => EncryptSecretBloc(user: widget.user),
|
|
child: MultiBlocListener(
|
|
listeners: [
|
|
BlocListener<EncryptSecretBloc, EncryptSecretState>(
|
|
listenWhen: (previous, current) =>
|
|
previous.isSignOut != current.isSignOut,
|
|
listener: (context, state) async {
|
|
if (state.isSignOut) {
|
|
await runAppFlowy();
|
|
}
|
|
},
|
|
),
|
|
BlocListener<EncryptSecretBloc, EncryptSecretState>(
|
|
listenWhen: (previous, current) =>
|
|
previous.successOrFail != current.successOrFail,
|
|
listener: (context, state) async {
|
|
state.successOrFail.fold(
|
|
() {},
|
|
(result) {
|
|
result.fold(
|
|
(unit) async {
|
|
await runAppFlowy();
|
|
},
|
|
(err) {
|
|
Log.error(err);
|
|
showSnackBarMessage(context, err.msg);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
],
|
|
child: BlocBuilder<EncryptSecretBloc, EncryptSecretState>(
|
|
builder: (context, state) {
|
|
final indicator = state.loadingState?.when(
|
|
loading: () => const Center(
|
|
child: CircularProgressIndicator.adaptive(),
|
|
),
|
|
finish: (result) => const SizedBox.shrink(),
|
|
) ??
|
|
const SizedBox.shrink();
|
|
return Center(
|
|
child: SizedBox(
|
|
width: 300,
|
|
height: 160,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Opacity(
|
|
opacity: 0.6,
|
|
child: FlowyText.medium(
|
|
"${LocaleKeys.settings_menu_inputEncryptPrompt.tr()} ${widget.user.email}",
|
|
fontSize: 14,
|
|
maxLines: 10,
|
|
),
|
|
),
|
|
const VSpace(6),
|
|
SizedBox(
|
|
width: 300,
|
|
child: FlowyTextField(
|
|
controller: _textEditingController,
|
|
hintText:
|
|
LocaleKeys.settings_menu_inputTextFieldHint.tr(),
|
|
onChanged: (p0) {},
|
|
),
|
|
),
|
|
OkCancelButton(
|
|
alignment: MainAxisAlignment.end,
|
|
onOkPressed: () {
|
|
context.read<EncryptSecretBloc>().add(
|
|
EncryptSecretEvent.setEncryptSecret(
|
|
_textEditingController.text,
|
|
),
|
|
);
|
|
},
|
|
onCancelPressed: () {
|
|
context.read<EncryptSecretBloc>().add(
|
|
const EncryptSecretEvent.cancelInputSecret(),
|
|
);
|
|
},
|
|
mode: TextButtonMode.normal,
|
|
),
|
|
const VSpace(6),
|
|
indicator,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|