Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update 2fa recovery page

AmanRajSinghMourya10dda28c0148
diff --git a/mobile/apps/photos/lib/ui/account/two_factor_recovery_page.dart b/mobile/apps/photos/lib/ui/account/two_factor_recovery_page.dart
index b6d6c569d3..4e7347eead 100644
--- a/mobile/apps/photos/lib/ui/account/two_factor_recovery_page.dart
+++ b/mobile/apps/photos/lib/ui/account/two_factor_recovery_page.dart
@@ -2,7 +2,12 @@ import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/models/account/two_factor.dart";
import 'package:photos/services/account/user_service.dart';
+import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/theme/text_style.dart";
+import "package:photos/ui/common/dynamic_fab.dart";
+import "package:photos/ui/components/buttons/button_widget_v2.dart";
+import "package:photos/ui/components/text_input_widget_v2.dart";
import 'package:photos/utils/dialog_util.dart';
class TwoFactorRecoveryPage extends StatefulWidget {
@@ -24,93 +29,120 @@ class TwoFactorRecoveryPage extends StatefulWidget {
}
class _TwoFactorRecoveryPageState extends State<TwoFactorRecoveryPage> {
- final _recoveryKey = TextEditingController();
+ final _recoveryKeyController = TextEditingController();
+ String _recoveryKey = '';
+
+ @override
+ void dispose() {
+ _recoveryKeyController.dispose();
+ super.dispose();
+ }
@override
Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
+
+ FloatingActionButtonLocation? fabLocation() {
+ if (isKeypadOpen) {
+ return null;
+ } else {
+ return FloatingActionButtonLocation.centerFloat;
+ }
+ }
+
return Scaffold(
+ resizeToAvoidBottomInset: isKeypadOpen,
+ backgroundColor: colorScheme.backgroundColour,
appBar: AppBar(
+ elevation: 0,
+ scrolledUnderElevation: 0,
+ backgroundColor: colorScheme.backgroundColour,
+ leading: IconButton(
+ icon: const Icon(Icons.arrow_back),
+ color: colorScheme.content,
+ onPressed: () {
+ Navigator.of(context).pop();
+ },
+ ),
title: Text(
- AppLocalizations.of(context).recoverAccount,
- style: const TextStyle(
- fontSize: 18,
+ "ente",
+ style: textTheme.h3Bold.copyWith(
+ fontFamily: "Montserrat",
),
),
+ centerTitle: true,
),
- body: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.max,
- children: [
- Padding(
- padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
- child: TextFormField(
- decoration: InputDecoration(
- hintText: AppLocalizations.of(context).enterYourRecoveryKey,
- contentPadding: const EdgeInsets.all(20),
- ),
- style: const TextStyle(
- fontSize: 14,
- fontFeatures: [FontFeature.tabularFigures()],
- ),
- controller: _recoveryKey,
- autofocus: false,
- autocorrect: false,
+ body: _getBody(colorScheme, textTheme),
+ floatingActionButton: DynamicFAB(
+ key: const ValueKey("recover2FAButton"),
+ isKeypadOpen: isKeypadOpen,
+ isFormValid: _recoveryKey.isNotEmpty,
+ buttonText: AppLocalizations.of(context).recover,
+ onPressedFunction: () async {
+ FocusScope.of(context).unfocus();
+ await UserService.instance.removeTwoFactor(
+ context,
+ widget.type,
+ widget.sessionID,
+ _recoveryKeyController.text,
+ widget.encryptedSecret,
+ widget.secretDecryptionNonce,
+ );
+ },
+ ),
+ floatingActionButtonLocation: fabLocation(),
+ floatingActionButtonAnimator: NoScalingAnimation(),
+ );
+ }
+
+ Widget _getBody(EnteColorScheme colorScheme, EnteTextTheme textTheme) {
+ return SafeArea(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ children: [
+ const SizedBox(height: 24),
+ TextInputWidgetV2(
+ label: AppLocalizations.of(context).recoveryKey,
+ hintText: AppLocalizations.of(context).enterYourRecoveryKey,
+ textEditingController: _recoveryKeyController,
+ autoCorrect: false,
keyboardType: TextInputType.multiline,
- maxLines: null,
- onChanged: (_) {
- setState(() {});
+ minLines: 4,
+ onChange: (value) {
+ final hasKey = value.isNotEmpty;
+ if ((_recoveryKey.isNotEmpty) != hasKey) {
+ setState(() {
+ _recoveryKey = value;
+ });
+ } else {
+ _recoveryKey = value;
+ }
},
),
- ),
- const Padding(padding: EdgeInsets.all(24)),
- Container(
- padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
- width: double.infinity,
- height: 64,
- child: OutlinedButton(
- onPressed: _recoveryKey.text.isNotEmpty
- ? () async {
- await UserService.instance.removeTwoFactor(
- context,
- widget.type,
- widget.sessionID,
- _recoveryKey.text,
- widget.encryptedSecret,
- widget.secretDecryptionNonce,
- );
- }
- : null,
- child: Text(AppLocalizations.of(context).recover),
- ),
- ),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () {
- showErrorDialog(
- context,
- AppLocalizations.of(context).contactSupport,
- AppLocalizations.of(context)
- .dropSupportEmail(supportEmail: "[email protected]"),
- );
- },
- child: Container(
- padding: const EdgeInsets.all(40),
- child: Center(
- child: Text(
- AppLocalizations.of(context).noRecoveryKey,
- style: TextStyle(
- decoration: TextDecoration.underline,
- fontSize: 12,
- color: getEnteColorScheme(context)
- .textBase
- .withValues(alpha: 0.9),
- ),
- ),
+ const SizedBox(height: 12),
+ Align(
+ alignment: Alignment.centerRight,
+ child: ButtonWidgetV2(
+ buttonType: ButtonTypeV2.link,
+ labelText: AppLocalizations.of(context).noRecoveryKey,
+ buttonSize: ButtonSizeV2.small,
+ onTap: () async {
+ // ignore: unawaited_futures
+ showErrorDialog(
+ context,
+ AppLocalizations.of(context).contactSupport,
+ AppLocalizations.of(context).dropSupportEmail(
+ supportEmail: "[email protected]",
+ ),
+ );
+ },
),
),
- ),
- ],
+ ],
+ ),
),
);
}