ente/lib/ui/account/recovery_page.dart

161 lines
5.5 KiB
Dart
Raw Normal View History

// @dart=2.9
2021-04-01 14:26:08 +00:00
import 'dart:ui';
2021-03-30 12:13:13 +00:00
import 'package:flutter/material.dart';
2021-04-01 14:26:08 +00:00
import 'package:photos/core/configuration.dart';
import 'package:photos/ui/account/password_entry_page.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/dynamic_fab.dart';
2021-04-01 14:26:08 +00:00
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/toast_util.dart';
2021-03-30 12:13:13 +00:00
2021-04-01 14:26:08 +00:00
class RecoveryPage extends StatefulWidget {
2021-03-30 12:13:13 +00:00
const RecoveryPage({Key key}) : super(key: key);
2021-04-01 14:26:08 +00:00
@override
2022-07-03 09:45:00 +00:00
State<RecoveryPage> createState() => _RecoveryPageState();
2021-04-01 14:26:08 +00:00
}
class _RecoveryPageState extends State<RecoveryPage> {
final _recoveryKey = TextEditingController();
2021-03-30 12:13:13 +00:00
@override
Widget build(BuildContext context) {
2022-06-15 06:48:23 +00:00
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
FloatingActionButtonLocation fabLocation() {
if (isKeypadOpen) {
return null;
} else {
return FloatingActionButtonLocation.centerFloat;
}
}
2021-03-30 12:13:13 +00:00
return Scaffold(
2022-06-15 06:48:23 +00:00
resizeToAvoidBottomInset: isKeypadOpen,
2021-03-30 12:13:13 +00:00
appBar: AppBar(
elevation: 0,
leading: IconButton(
2022-07-04 06:02:17 +00:00
icon: const Icon(Icons.arrow_back),
color: Theme.of(context).iconTheme.color,
onPressed: () {
Navigator.of(context).pop();
},
2021-03-30 12:13:13 +00:00
),
),
floatingActionButton: DynamicFAB(
2022-06-15 06:48:23 +00:00
isKeypadOpen: isKeypadOpen,
2022-06-11 08:23:52 +00:00
isFormValid: _recoveryKey.text.isNotEmpty,
buttonText: 'Recover',
onPressedFunction: () async {
FocusScope.of(context).unfocus();
2022-06-11 08:23:52 +00:00
final dialog = createProgressDialog(context, "Decrypting...");
await dialog.show();
try {
await Configuration.instance.recover(_recoveryKey.text.trim());
await dialog.hide();
showToast(context, "Recovery successful!");
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: const PasswordEntryPage(
2022-06-11 08:23:52 +00:00
mode: PasswordEntryMode.reset,
),
);
},
),
);
} catch (e) {
await dialog.hide();
String errMessage = 'the recovery key you entered is incorrect';
if (e is AssertionError) {
errMessage = '$errMessage : ${e.message}';
}
2022-06-18 12:23:51 +00:00
showErrorDialog(context, "Incorrect recovery key", errMessage);
2022-06-11 08:23:52 +00:00
}
},
),
2022-06-15 06:48:23 +00:00
floatingActionButtonLocation: fabLocation(),
2022-05-30 15:43:33 +00:00
floatingActionButtonAnimator: NoScalingAnimation(),
2021-03-30 12:13:13 +00:00
body: Column(
children: [
Expanded(
child: ListView(
children: [
Padding(
2022-07-03 09:45:00 +00:00
padding:
const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
2022-06-11 08:23:52 +00:00
child: Text(
'Forgot password',
style: Theme.of(context).textTheme.headline4,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
child: TextFormField(
decoration: InputDecoration(
filled: true,
2022-05-30 14:13:19 +00:00
hintText: "Enter your recovery key",
2022-07-04 06:02:17 +00:00
contentPadding: const EdgeInsets.all(20),
border: UnderlineInputBorder(
2022-06-11 08:23:52 +00:00
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6),
),
),
2022-07-04 06:02:17 +00:00
style: const TextStyle(
fontSize: 14,
2022-07-04 06:02:17 +00:00
fontFeatures: [FontFeature.tabularFigures()],
),
controller: _recoveryKey,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (_) {
setState(() {});
},
),
),
2022-07-04 06:02:17 +00:00
const Padding(
padding: EdgeInsets.symmetric(vertical: 18),
child: Divider(
thickness: 1,
),
),
Row(
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
showErrorDialog(
context,
"Sorry",
"Due to the nature of our end-to-end encryption protocol, your data cannot be decrypted without your password or recovery key",
);
},
child: Container(
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text(
2022-05-30 14:13:19 +00:00
"No recovery key?",
2022-07-03 09:45:00 +00:00
style:
Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 14,
decoration: TextDecoration.underline,
),
),
),
),
),
],
2021-04-01 14:26:08 +00:00
),
],
2021-04-01 14:26:08 +00:00
),
),
2021-03-30 12:13:13 +00:00
],
),
);
}
}