2022-07-08 08:51:01 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2022-07-08 07:27:04 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-11 10:53:20 +00:00
|
|
|
import "package:logging/logging.dart";
|
2022-07-08 08:51:01 +00:00
|
|
|
import 'package:photos/core/configuration.dart';
|
|
|
|
import 'package:photos/models/delete_account.dart';
|
2022-09-05 10:32:04 +00:00
|
|
|
import 'package:photos/services/local_authentication_service.dart';
|
2022-07-08 08:51:01 +00:00
|
|
|
import 'package:photos/services/user_service.dart';
|
2022-12-27 07:21:52 +00:00
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2022-12-22 11:11:40 +00:00
|
|
|
import 'package:photos/ui/components/button_widget.dart';
|
2022-12-27 07:14:25 +00:00
|
|
|
import 'package:photos/ui/components/models/button_type.dart';
|
2022-07-08 08:51:01 +00:00
|
|
|
import 'package:photos/utils/crypto_util.dart';
|
2022-12-30 02:33:03 +00:00
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
2022-07-11 10:16:53 +00:00
|
|
|
import 'package:photos/utils/email_util.dart';
|
2022-07-08 07:27:04 +00:00
|
|
|
|
|
|
|
class DeleteAccountPage extends StatelessWidget {
|
|
|
|
const DeleteAccountPage({
|
2022-12-30 09:44:52 +00:00
|
|
|
Key? key,
|
2022-07-08 07:27:04 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-27 07:21:52 +00:00
|
|
|
final colorScheme = getEnteColorScheme(context);
|
2022-07-08 07:27:04 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
title: const Text("Delete account"),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
color: Theme.of(context).iconTheme.color,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Padding(
|
2022-07-12 05:30:19 +00:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
|
2022-07-08 07:27:04 +00:00
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-07-12 05:30:19 +00:00
|
|
|
Image.asset(
|
|
|
|
'assets/broken_heart.png',
|
|
|
|
width: 200,
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
2022-07-12 05:30:19 +00:00
|
|
|
const SizedBox(
|
2022-07-12 06:08:12 +00:00
|
|
|
height: 24,
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: Text(
|
|
|
|
"We'll be sorry to see you go. Are you facing some issue?",
|
2022-12-27 07:21:52 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
2022-12-30 09:44:52 +00:00
|
|
|
.subtitle1!
|
2022-12-27 07:21:52 +00:00
|
|
|
.copyWith(color: colorScheme.textMuted),
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
2022-07-11 17:39:49 +00:00
|
|
|
height: 12,
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
|
|
|
RichText(
|
|
|
|
// textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(
|
|
|
|
children: const [
|
|
|
|
TextSpan(text: "Please write to us at "),
|
|
|
|
TextSpan(
|
|
|
|
text: "feedback@ente.io",
|
|
|
|
style: TextStyle(color: Color.fromRGBO(29, 185, 84, 1)),
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: ", maybe there is a way we can help.",
|
|
|
|
),
|
|
|
|
],
|
2022-12-27 07:21:52 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
2022-12-30 09:44:52 +00:00
|
|
|
.subtitle1!
|
2022-12-27 07:21:52 +00:00
|
|
|
.copyWith(color: colorScheme.textMuted),
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
|
|
|
),
|
2022-07-11 17:39:49 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
2022-07-08 07:27:04 +00:00
|
|
|
),
|
2022-12-27 07:14:25 +00:00
|
|
|
ButtonWidget(
|
|
|
|
buttonType: ButtonType.primary,
|
|
|
|
labelText: "Yes, send feedback",
|
|
|
|
icon: Icons.check_outlined,
|
2022-07-08 07:27:04 +00:00
|
|
|
onTap: () async {
|
2022-07-11 10:16:53 +00:00
|
|
|
await sendEmail(
|
|
|
|
context,
|
|
|
|
to: 'feedback@ente.io',
|
|
|
|
subject: '[Feedback]',
|
2022-07-08 07:27:04 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-12-27 07:14:25 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
ButtonWidget(
|
|
|
|
buttonType: ButtonType.tertiaryCritical,
|
|
|
|
labelText: "No, delete account",
|
|
|
|
icon: Icons.no_accounts_outlined,
|
|
|
|
onTap: () async => {await _initiateDelete(context)},
|
2022-12-27 08:07:10 +00:00
|
|
|
shouldSurfaceExecutionStates: false,
|
2022-12-27 07:14:25 +00:00
|
|
|
)
|
2022-07-08 07:27:04 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-08 08:51:01 +00:00
|
|
|
Future<void> _initiateDelete(BuildContext context) async {
|
|
|
|
final deleteChallengeResponse =
|
|
|
|
await UserService.instance.getDeleteChallenge(context);
|
|
|
|
if (deleteChallengeResponse == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (deleteChallengeResponse.allowDelete) {
|
|
|
|
await _confirmAndDelete(context, deleteChallengeResponse);
|
|
|
|
} else {
|
|
|
|
await _requestEmailForDeletion(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _confirmAndDelete(
|
|
|
|
BuildContext context,
|
|
|
|
DeleteChallengeResponse response,
|
|
|
|
) async {
|
2022-09-06 08:35:34 +00:00
|
|
|
final hasAuthenticated =
|
2022-09-05 12:29:24 +00:00
|
|
|
await LocalAuthenticationService.instance.requestLocalAuthentication(
|
2022-09-02 13:51:02 +00:00
|
|
|
context,
|
|
|
|
"Please authenticate to initiate account deletion",
|
|
|
|
);
|
2022-08-30 04:47:17 +00:00
|
|
|
|
2022-09-06 08:35:34 +00:00
|
|
|
if (hasAuthenticated) {
|
2023-01-27 12:08:53 +00:00
|
|
|
final choice = await showChoiceDialog(
|
2023-01-07 13:16:59 +00:00
|
|
|
context,
|
2022-12-22 11:11:40 +00:00
|
|
|
title: 'Are you sure you want to delete your account?',
|
|
|
|
body:
|
|
|
|
'Your uploaded data will be scheduled for deletion, and your account'
|
2022-12-26 13:44:48 +00:00
|
|
|
' will be permanently deleted. \n\nThis action is not reversible.',
|
2022-12-26 12:06:53 +00:00
|
|
|
firstButtonLabel: "Delete my account",
|
|
|
|
isCritical: true,
|
2022-12-26 09:44:04 +00:00
|
|
|
firstButtonOnTap: () async {
|
|
|
|
final decryptChallenge = CryptoUtil.openSealSync(
|
2023-02-03 04:41:45 +00:00
|
|
|
CryptoUtil.base642bin(response.encryptedChallenge),
|
|
|
|
CryptoUtil.base642bin(
|
2022-12-30 09:44:52 +00:00
|
|
|
Configuration.instance.getKeyAttributes()!.publicKey,
|
2022-12-26 09:44:04 +00:00
|
|
|
),
|
2022-12-30 09:44:52 +00:00
|
|
|
Configuration.instance.getSecretKey()!,
|
2022-12-26 09:44:04 +00:00
|
|
|
);
|
|
|
|
final challengeResponseStr = utf8.decode(decryptChallenge);
|
|
|
|
await UserService.instance
|
|
|
|
.deleteAccount(context, challengeResponseStr);
|
|
|
|
},
|
2022-09-03 03:02:42 +00:00
|
|
|
);
|
2023-02-10 07:22:16 +00:00
|
|
|
if (choice!.action == ButtonAction.error) {
|
2022-12-26 11:09:29 +00:00
|
|
|
showGenericErrorDialog(context: context);
|
2022-12-22 13:38:39 +00:00
|
|
|
}
|
2023-02-10 07:22:16 +00:00
|
|
|
if (choice.action != ButtonAction.first) {
|
2022-09-03 03:02:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-11 10:53:20 +00:00
|
|
|
|
2022-12-22 11:11:40 +00:00
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
2023-03-11 10:53:20 +00:00
|
|
|
await showTextInputDialog(
|
|
|
|
context,
|
|
|
|
title: "Your account was deleted. Would you like to leave us a note?",
|
|
|
|
submitButtonLabel: "Send",
|
|
|
|
hintText: "Optional, as short as you like...",
|
|
|
|
alwaysShowSuccessState: true,
|
|
|
|
textCapitalization: TextCapitalization.words,
|
|
|
|
onSubmit: (String text) async {
|
|
|
|
// indicates user cancelled the rename request
|
|
|
|
if (text == "" || text.trim().isEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await UserService.instance.sendFeedback(context, text);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logger("Delete account").severe("Failed to send feedback", e, s);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2022-07-08 07:27:04 +00:00
|
|
|
}
|
2022-07-08 08:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _requestEmailForDeletion(BuildContext context) async {
|
2022-08-29 14:43:31 +00:00
|
|
|
final AlertDialog alert = AlertDialog(
|
2022-07-08 08:51:01 +00:00
|
|
|
title: const Text(
|
|
|
|
"Delete account",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
content: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
children: [
|
|
|
|
const TextSpan(
|
|
|
|
text: "Please send an email to ",
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: "account-deletion@ente.io",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.orange[300],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const TextSpan(
|
|
|
|
text:
|
|
|
|
" from your registered email address.\n\nYour request will be processed within 72 hours.",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
height: 1.5,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
child: const Text(
|
|
|
|
"Send email",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop('dialog');
|
2022-07-11 10:16:53 +00:00
|
|
|
await sendEmail(
|
|
|
|
context,
|
|
|
|
to: 'account-deletion@ente.io',
|
|
|
|
subject: '[Delete account]',
|
|
|
|
);
|
2022-07-08 08:51:01 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
"Ok",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop('dialog');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
2022-07-08 07:27:04 +00:00
|
|
|
}
|
|
|
|
}
|