2022-07-08 08:51:01 +00:00
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2022-07-08 07:27:04 +00:00
|
|
|
|
import 'package:flutter/material.dart';
|
2022-07-08 08:51:01 +00:00
|
|
|
|
import 'package:photos/core/configuration.dart';
|
|
|
|
|
import 'package:photos/models/delete_account.dart';
|
|
|
|
|
import 'package:photos/services/user_service.dart';
|
2022-12-27 07:21:52 +00:00
|
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2023-03-10 08:08:51 +00:00
|
|
|
|
import 'package:photos/ui/components/buttons/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
|
|
|
|
|
2023-03-15 12:21:39 +00:00
|
|
|
|
class DeleteAccountPage extends StatefulWidget {
|
2022-07-08 07:27:04 +00:00
|
|
|
|
const DeleteAccountPage({
|
2022-12-30 09:44:52 +00:00
|
|
|
|
Key? key,
|
2022-07-08 07:27:04 +00:00
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
2023-03-15 12:21:39 +00:00
|
|
|
|
@override
|
|
|
|
|
State<DeleteAccountPage> createState() => _DeleteAccountPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DeleteAccountPageState extends State<DeleteAccountPage> {
|
|
|
|
|
bool _hasConfirmedDeletion = false;
|
|
|
|
|
final _feedbackTextCtrl = TextEditingController();
|
|
|
|
|
final _focusNode = FocusNode();
|
|
|
|
|
final String _defaultSelection = 'Select reason';
|
|
|
|
|
late String dropdownValue = _defaultSelection;
|
|
|
|
|
late List<String> deletionReason = [
|
|
|
|
|
_defaultSelection,
|
|
|
|
|
'It’s missing a key feature that I need',
|
|
|
|
|
'I found another service that I like better',
|
|
|
|
|
'I use a different account',
|
|
|
|
|
'My reason isn’t listed',
|
|
|
|
|
];
|
|
|
|
|
|
2022-07-08 07:27:04 +00:00
|
|
|
|
@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,
|
2023-03-15 12:21:39 +00:00
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
2022-07-08 07:27:04 +00:00
|
|
|
|
children: [
|
2023-03-15 12:21:39 +00:00
|
|
|
|
Text(
|
|
|
|
|
"What is the main reason you are deleting your account?",
|
|
|
|
|
style: getEnteTextTheme(context).body,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: 48,
|
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: colorScheme.fillFaint,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
|
alignment: AlignmentDirectional.topStart,
|
|
|
|
|
value: dropdownValue,
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.expand_more_outlined,
|
|
|
|
|
color: colorScheme.strokeMuted,
|
|
|
|
|
),
|
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
|
setState(() {
|
|
|
|
|
dropdownValue = newValue!;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
underline: const SizedBox(),
|
|
|
|
|
items: deletionReason
|
|
|
|
|
.map<DropdownMenuItem<String>>((String value) {
|
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
|
value: value,
|
|
|
|
|
enabled: value != _defaultSelection,
|
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
|
child: Text(
|
|
|
|
|
value,
|
|
|
|
|
style: value != _defaultSelection
|
|
|
|
|
? getEnteTextTheme(context).small
|
|
|
|
|
: getEnteTextTheme(context).smallMuted,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
Text(
|
|
|
|
|
"We are sorry to see you go. Please explain why you are "
|
|
|
|
|
"leaving to help us improve.",
|
|
|
|
|
style: getEnteTextTheme(context).body,
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
TextFormField(
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderSide:
|
|
|
|
|
BorderSide(color: colorScheme.strokeFaint, width: 1),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderSide:
|
|
|
|
|
BorderSide(color: colorScheme.strokeFaint, width: 1),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: Colors.transparent,
|
|
|
|
|
hintText: "Feedback",
|
|
|
|
|
contentPadding: const EdgeInsets.all(12),
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
controller: _feedbackTextCtrl,
|
|
|
|
|
autofocus: false,
|
|
|
|
|
autocorrect: false,
|
|
|
|
|
focusNode: _focusNode,
|
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
|
minLines: 3,
|
|
|
|
|
maxLines: null,
|
|
|
|
|
onChanged: (_) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
(_focusNode.hasFocus || _hasConfirmedDeletion) &&
|
|
|
|
|
_feedbackTextCtrl.text.trim().length < 10
|
|
|
|
|
? SizedBox(
|
|
|
|
|
height: 42,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 4.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
"This field requires a minimum of 10 "
|
|
|
|
|
"characters",
|
|
|
|
|
style: getEnteTextTheme(context)
|
|
|
|
|
.smallBold
|
|
|
|
|
.copyWith(color: colorScheme.warning700),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: const SizedBox(height: 42),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Checkbox(
|
|
|
|
|
value: _hasConfirmedDeletion,
|
|
|
|
|
side: CheckboxTheme.of(context).side,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_hasConfirmedDeletion = value!;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
"Yes, I want to permanently delete this account and "
|
|
|
|
|
"all its data.",
|
|
|
|
|
style: getEnteTextTheme(context).bodyMuted,
|
2023-03-15 12:48:32 +00:00
|
|
|
|
textAlign: TextAlign.left,
|
2023-03-15 12:21:39 +00:00
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
ButtonWidget(
|
|
|
|
|
buttonType: ButtonType.critical,
|
2023-03-15 12:48:32 +00:00
|
|
|
|
labelText: "Confirm Account Deletion",
|
2023-03-15 12:21:39 +00:00
|
|
|
|
isDisabled: !_hasConfirmedDeletion ||
|
|
|
|
|
_defaultSelection == dropdownValue ||
|
|
|
|
|
_feedbackTextCtrl.text.trim().length < 10,
|
|
|
|
|
onTap: () async => {await _initiateDelete(context)},
|
|
|
|
|
shouldSurfaceExecutionStates: false,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
ButtonWidget(
|
|
|
|
|
buttonType: ButtonType.secondary,
|
|
|
|
|
labelText: "Cancel",
|
|
|
|
|
onTap: () async {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
2022-07-08 07:27:04 +00:00
|
|
|
|
),
|
2023-03-15 12:21:39 +00:00
|
|
|
|
const SafeArea(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: 12,
|
|
|
|
|
),
|
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 {
|
2023-03-15 09:56:45 +00:00
|
|
|
|
final choice = await showChoiceDialog(
|
2022-09-02 13:51:02 +00:00
|
|
|
|
context,
|
2023-03-15 09:56:45 +00:00
|
|
|
|
title: 'Are you sure you want to delete your account?',
|
|
|
|
|
body:
|
|
|
|
|
'Your uploaded data will be scheduled for deletion, and your account'
|
|
|
|
|
' will be permanently deleted. \n\nThis action is not reversible.',
|
|
|
|
|
firstButtonLabel: "Delete my account",
|
|
|
|
|
isCritical: true,
|
|
|
|
|
firstButtonOnTap: () async {
|
|
|
|
|
final decryptChallenge = CryptoUtil.openSealSync(
|
|
|
|
|
CryptoUtil.base642bin(response.encryptedChallenge),
|
|
|
|
|
CryptoUtil.base642bin(
|
|
|
|
|
Configuration.instance.getKeyAttributes()!.publicKey,
|
|
|
|
|
),
|
|
|
|
|
Configuration.instance.getSecretKey()!,
|
|
|
|
|
);
|
|
|
|
|
final challengeResponseStr = utf8.decode(decryptChallenge);
|
|
|
|
|
await UserService.instance.deleteAccount(context, challengeResponseStr);
|
|
|
|
|
},
|
2022-09-02 13:51:02 +00:00
|
|
|
|
);
|
2023-03-15 09:56:45 +00:00
|
|
|
|
if (choice!.action == ButtonAction.error) {
|
|
|
|
|
showGenericErrorDialog(context: context);
|
2022-07-08 07:27:04 +00:00
|
|
|
|
}
|
2023-03-15 09:56:45 +00:00
|
|
|
|
if (choice.action != ButtonAction.first) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
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
|
|
|
|
}
|
|
|
|
|
}
|