ente/lib/ui/settings/account_section_widget.dart

126 lines
4.1 KiB
Dart
Raw Normal View History

// @dart=2.9
import 'package:flutter/material.dart';
2021-07-28 15:41:45 +00:00
import 'package:flutter_sodium/flutter_sodium.dart';
import 'package:photos/services/local_authentication_service.dart';
2021-07-28 15:41:45 +00:00
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/account/change_email_dialog.dart';
import 'package:photos/ui/account/password_entry_page.dart';
import 'package:photos/ui/account/recovery_key_page.dart';
import 'package:photos/ui/components/captioned_text_widget.dart';
import 'package:photos/ui/components/expandable_menu_item_widget.dart';
import 'package:photos/ui/components/menu_item_widget.dart';
import 'package:photos/ui/settings/common_settings.dart';
2021-07-28 15:41:45 +00:00
import 'package:photos/utils/dialog_util.dart';
2022-04-06 17:41:24 +00:00
import 'package:photos/utils/navigation_util.dart';
class AccountSectionWidget extends StatelessWidget {
const AccountSectionWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ExpandableMenuItemWidget(
title: "Account",
selectionOptionsWidget: _getSectionOptions(context),
leadingIcon: Icons.account_circle_outlined,
);
}
Column _getSectionOptions(BuildContext context) {
2021-07-27 14:51:45 +00:00
return Column(
children: [
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
2022-10-05 13:57:32 +00:00
title: "Recovery key",
),
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
2021-07-27 14:51:45 +00:00
onTap: () async {
2022-09-06 08:35:34 +00:00
final hasAuthenticated = await LocalAuthenticationService.instance
.requestLocalAuthentication(
context,
"Please authenticate to view your recovery key",
);
2022-09-06 08:35:34 +00:00
if (hasAuthenticated) {
2022-09-03 03:02:42 +00:00
String recoveryKey;
try {
recoveryKey = await _getOrCreateRecoveryKey(context);
2022-09-03 03:02:42 +00:00
} catch (e) {
showGenericErrorDialog(context);
return;
}
routeToPage(
context,
RecoveryKeyPage(
recoveryKey,
"OK",
showAppBar: true,
onDone: () {},
),
);
2021-07-28 15:41:45 +00:00
}
},
),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
2022-10-05 13:57:32 +00:00
title: "Change email",
),
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
2021-07-28 18:06:30 +00:00
onTap: () async {
2022-09-06 08:35:34 +00:00
final hasAuthenticated = await LocalAuthenticationService.instance
.requestLocalAuthentication(
context,
"Please authenticate to change your email",
);
2022-09-06 08:35:34 +00:00
if (hasAuthenticated) {
2022-09-03 03:02:42 +00:00
showDialog(
context: context,
builder: (BuildContext context) {
return const ChangeEmailDialog();
},
barrierColor: Colors.black.withOpacity(0.85),
barrierDismissible: false,
);
}
2021-07-28 18:06:30 +00:00
},
),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
2022-10-05 13:57:32 +00:00
title: "Change password",
),
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
2021-07-28 15:41:45 +00:00
onTap: () async {
2022-09-06 08:35:34 +00:00
final hasAuthenticated = await LocalAuthenticationService.instance
.requestLocalAuthentication(
context,
"Please authenticate to change your password",
);
2022-09-06 08:35:34 +00:00
if (hasAuthenticated) {
2022-09-03 03:02:42 +00:00
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return const PasswordEntryPage(
mode: PasswordEntryMode.update,
);
},
),
);
}
2021-07-28 15:41:45 +00:00
},
2021-07-27 14:51:45 +00:00
),
],
);
}
Future<String> _getOrCreateRecoveryKey(BuildContext context) async {
2021-07-28 15:41:45 +00:00
return Sodium.bin2hex(
2022-06-11 08:23:52 +00:00
await UserService.instance.getOrCreateRecoveryKey(context),
);
}
}