2022-11-06 10:16:14 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-04-19 09:35:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:flutter_sodium/flutter_sodium.dart';
|
2022-09-05 10:32:04 +00:00
|
|
|
import 'package:photos/services/local_authentication_service.dart';
|
2021-07-28 15:41:45 +00:00
|
|
|
import 'package:photos/services/user_service.dart';
|
2022-10-21 13:37:57 +00:00
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/account/change_email_dialog.dart';
|
2022-12-07 03:22:18 +00:00
|
|
|
import 'package:photos/ui/account/delete_account_page.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/account/password_entry_page.dart';
|
|
|
|
import 'package:photos/ui/account/recovery_key_page.dart';
|
2022-10-04 04:16:40 +00:00
|
|
|
import 'package:photos/ui/components/captioned_text_widget.dart';
|
2022-10-05 11:48:56 +00:00
|
|
|
import 'package:photos/ui/components/expandable_menu_item_widget.dart';
|
2023-01-31 12:21:57 +00:00
|
|
|
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
|
2022-03-08 19:43:51 +00:00
|
|
|
import 'package:photos/ui/settings/common_settings.dart';
|
2022-12-30 02:33:03 +00:00
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
2022-04-06 17:41:24 +00:00
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
2021-04-19 09:35:22 +00:00
|
|
|
|
2022-10-06 03:52:05 +00:00
|
|
|
class AccountSectionWidget extends StatelessWidget {
|
2022-12-27 18:01:23 +00:00
|
|
|
const AccountSectionWidget({Key? key}) : super(key: key);
|
2021-04-19 09:35:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-05 11:48:56 +00:00
|
|
|
return ExpandableMenuItemWidget(
|
|
|
|
title: "Account",
|
|
|
|
selectionOptionsWidget: _getSectionOptions(context),
|
|
|
|
leadingIcon: Icons.account_circle_outlined,
|
2022-03-08 19:43:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Column _getSectionOptions(BuildContext context) {
|
2021-07-27 14:51:45 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-04 13:55:39 +00:00
|
|
|
MenuItemWidget(
|
|
|
|
captionedTextWidget: const CaptionedTextWidget(
|
2022-10-05 13:57:32 +00:00
|
|
|
title: "Recovery key",
|
2022-10-04 13:55:39 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:55:39 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 03:44:54 +00:00
|
|
|
showOnlyLoadingState: 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(
|
2022-09-02 13:51:02 +00:00
|
|
|
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 {
|
2022-10-06 03:52:05 +00:00
|
|
|
recoveryKey = await _getOrCreateRecoveryKey(context);
|
2022-09-03 03:02:42 +00:00
|
|
|
} catch (e) {
|
2022-12-26 11:09:29 +00:00
|
|
|
await showGenericErrorDialog(context: context);
|
2022-09-03 03:02:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-11-06 10:16:14 +00:00
|
|
|
unawaited(
|
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
RecoveryKeyPage(
|
|
|
|
recoveryKey,
|
|
|
|
"OK",
|
|
|
|
showAppBar: true,
|
|
|
|
onDone: () {},
|
|
|
|
),
|
2022-09-03 03:02:42 +00:00
|
|
|
),
|
|
|
|
);
|
2021-07-28 15:41:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-04 13:55:39 +00:00
|
|
|
MenuItemWidget(
|
|
|
|
captionedTextWidget: const CaptionedTextWidget(
|
2022-10-05 13:57:32 +00:00
|
|
|
title: "Change email",
|
2022-10-04 13:55:39 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:55:39 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 03:44:54 +00:00
|
|
|
showOnlyLoadingState: 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(
|
2022-09-02 13:51:02 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
),
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-04 13:55:39 +00:00
|
|
|
MenuItemWidget(
|
|
|
|
captionedTextWidget: const CaptionedTextWidget(
|
2022-10-05 13:57:32 +00:00
|
|
|
title: "Change password",
|
2022-10-04 13:55:39 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:55:39 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 03:44:54 +00:00
|
|
|
showOnlyLoadingState: 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(
|
2022-09-02 13:51:02 +00:00
|
|
|
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
|
|
|
),
|
2022-10-10 11:41:39 +00:00
|
|
|
sectionOptionSpacing,
|
2022-12-07 03:22:18 +00:00
|
|
|
MenuItemWidget(
|
|
|
|
captionedTextWidget: const CaptionedTextWidget(
|
|
|
|
title: "Logout",
|
|
|
|
),
|
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 01:42:26 +00:00
|
|
|
onTap: () async {
|
2022-12-07 03:22:18 +00:00
|
|
|
_onLogoutTapped(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
sectionOptionSpacing,
|
|
|
|
MenuItemWidget(
|
|
|
|
captionedTextWidget: const CaptionedTextWidget(
|
|
|
|
title: "Delete account",
|
|
|
|
),
|
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 01:42:26 +00:00
|
|
|
onTap: () async {
|
2022-12-07 03:22:18 +00:00
|
|
|
routeToPage(context, const DeleteAccountPage());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
sectionOptionSpacing,
|
2021-07-27 14:51:45 +00:00
|
|
|
],
|
2021-04-19 09:35:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-06 03:52:05 +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),
|
|
|
|
);
|
2021-04-19 09:35:22 +00:00
|
|
|
}
|
2022-12-07 03:22:18 +00:00
|
|
|
|
2023-01-27 13:00:32 +00:00
|
|
|
void _onLogoutTapped(BuildContext context) {
|
2023-01-27 09:48:14 +00:00
|
|
|
showChoiceActionSheet(
|
|
|
|
context,
|
|
|
|
title: "Are you sure you want to logout?",
|
|
|
|
firstButtonLabel: "Yes, logout",
|
|
|
|
isCritical: true,
|
|
|
|
firstButtonOnTap: () async {
|
|
|
|
await UserService.instance.logout(context);
|
2022-12-07 03:22:18 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-04-19 09:35:22 +00:00
|
|
|
}
|