From 31ffb48e0f790dd1519f17fb14cb40abe52a0249 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:02:37 +0530 Subject: [PATCH] Disable emailMFA: request for password if SRP setup is not done --- .../request_pwd_verification_page.dart | 60 +------------------ lib/ui/settings/security_section_widget.dart | 11 ++++ 2 files changed, 13 insertions(+), 58 deletions(-) diff --git a/lib/ui/account/request_pwd_verification_page.dart b/lib/ui/account/request_pwd_verification_page.dart index a4064ae125..02be123479 100644 --- a/lib/ui/account/request_pwd_verification_page.dart +++ b/lib/ui/account/request_pwd_verification_page.dart @@ -3,7 +3,6 @@ import "dart:typed_data"; import 'package:ente_auth/core/configuration.dart'; import "package:ente_auth/l10n/l10n.dart"; -import "package:ente_auth/services/user_service.dart"; import "package:ente_auth/theme/ente_theme.dart"; import 'package:ente_auth/ui/common/dynamic_fab.dart'; import "package:ente_auth/utils/crypto_util.dart"; @@ -75,7 +74,7 @@ class _RequestPasswordVerificationPageState key: const ValueKey("verifyPasswordButton"), isKeypadOpen: isKeypadOpen, isFormValid: _passwordController.text.isNotEmpty, - buttonText: context.l10n.logInLabel, + buttonText: context.l10n.verifyPassword, onPressedFunction: () async { FocusScope.of(context).unfocus(); final dialog = createProgressDialog(context, context.l10n.pleaseWait); @@ -96,6 +95,7 @@ class _RequestPasswordVerificationPageState dialog.show(); // pop await widget.onPasswordVerified(keyEncryptionKey); + dialog.hide(); Navigator.of(context).pop(true); } catch (e, s) { _logger.severe("Error while verifying password", e, s); @@ -206,62 +206,6 @@ class _RequestPasswordVerificationPageState thickness: 1, ), ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - await UserService.instance.sendOtt( - context, - email!, - isResetPasswordScreen: true, - ); - }, - child: Center( - child: Text( - context.l10n.forgotPassword, - style: Theme.of(context) - .textTheme - .titleMedium! - .copyWith( - fontSize: 14, - decoration: TextDecoration.underline, - ), - ), - ), - ), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - final dialog = createProgressDialog( - context, - context.l10n.pleaseWait, - ); - await dialog.show(); - await Configuration.instance.logout(); - await dialog.hide(); - Navigator.of(context) - .popUntil((route) => route.isFirst); - }, - child: Center( - child: Text( - context.l10n.changeEmail, - style: Theme.of(context) - .textTheme - .titleMedium! - .copyWith( - fontSize: 14, - decoration: TextDecoration.underline, - ), - ), - ), - ), - ], - ), - ) ], ), ), diff --git a/lib/ui/settings/security_section_widget.dart b/lib/ui/settings/security_section_widget.dart index bb5f833dc6..2ea3695f98 100644 --- a/lib/ui/settings/security_section_widget.dart +++ b/lib/ui/settings/security_section_widget.dart @@ -1,17 +1,21 @@ import 'dart:async'; +import 'dart:typed_data'; import 'package:ente_auth/core/configuration.dart'; import 'package:ente_auth/l10n/l10n.dart'; +import 'package:ente_auth/models/user_details.dart'; import 'package:ente_auth/services/local_authentication_service.dart'; import 'package:ente_auth/services/user_service.dart'; import 'package:ente_auth/theme/ente_theme.dart'; import 'package:ente_auth/ui/account/recovery_key_page.dart'; +import 'package:ente_auth/ui/account/request_pwd_verification_page.dart'; import 'package:ente_auth/ui/account/sessions_page.dart'; import 'package:ente_auth/ui/components/captioned_text_widget.dart'; import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart'; import 'package:ente_auth/ui/components/menu_item_widget.dart'; import 'package:ente_auth/ui/components/toggle_switch_widget.dart'; import 'package:ente_auth/ui/settings/common_settings.dart'; +import 'package:ente_auth/utils/crypto_util.dart'; import 'package:ente_auth/utils/dialog_util.dart'; import 'package:ente_auth/utils/navigation_util.dart'; import 'package:ente_auth/utils/toast_util.dart'; @@ -169,6 +173,13 @@ class _SecuritySectionWidgetState extends State { Future updateEmailMFA(bool isEnabled) async { try { + final UserDetails details = await UserService.instance.getUserDetailsV2(memoryCount: false); + if(details.profileData?.canDisableEmailMFA == false) { + await routeToPage(context, RequestPasswordVerificationPage(onPasswordVerified: (Uint8List keyEncryptionKey) async { + final Uint8List loginKey = await CryptoUtil.deriveLoginKey(keyEncryptionKey); + await UserService.instance.registerOrUpdateSrp(loginKey); + },),); + } await UserService.instance.updateEmailMFA(isEnabled); } catch (e) { showToast(context, context.l10n.somethingWentWrongMessage);