Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] show lock when app starts & authenticate to change lock settings

Aman Raj Singh Mourya11da0704c635
diff --git a/mobile/lib/services/local_authentication_service.dart b/mobile/lib/services/local_authentication_service.dart
index 3ff5d381d6..75925aa7b6 100644
--- a/mobile/lib/services/local_authentication_service.dart
+++ b/mobile/lib/services/local_authentication_service.dart
@@ -3,10 +3,6 @@ import "dart:async";
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
import 'package:photos/core/configuration.dart';
-import "package:photos/generated/l10n.dart";
-import "package:photos/ui/components/buttons/button_widget.dart";
-import "package:photos/ui/components/dialog_widget.dart";
-import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_password.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart";
import 'package:photos/ui/tools/app_lock.dart';
@@ -58,23 +54,6 @@ class LocalAuthenticationService {
);
if (result) {
return true;
- } else {
- await showDialogWidget(
- context: context,
- title: 'Password does not match',
- icon: Icons.lock,
- body: 'Please re-enter the password.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
- return false;
}
}
if (savedPin != null) {
@@ -90,23 +69,6 @@ class LocalAuthenticationService {
);
if (result) {
return true;
- } else {
- await showDialogWidget(
- context: context,
- title: 'Pin does not match',
- icon: Icons.lock,
- body: 'Please re-enter the pin.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
- return false;
}
}
return false;
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
index 7cd7450b2f..5b7f151a58 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
@@ -1,7 +1,5 @@
import "package:flutter/material.dart";
import "package:photos/core/configuration.dart";
-import "package:photos/generated/l10n.dart";
-import "package:photos/services/local_authentication_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/captioned_text_widget.dart";
import "package:photos/ui/components/divider_widget.dart";
@@ -29,7 +27,9 @@ class _LockScreenOptionState extends State<LockScreenOption> {
void initState() {
isPasswordEnabled = _configuration.isPasswordSet();
isPinEnabled = _configuration.isPinSet();
- appLock = isPinEnabled || isPasswordEnabled;
+ appLock = isPinEnabled ||
+ isPasswordEnabled ||
+ !_configuration.shouldShowLockScreen();
super.initState();
}
@@ -79,34 +79,38 @@ class _LockScreenOptionState extends State<LockScreenOption> {
});
}
- Future<void> _onToggleSwitch() async {
- bool result;
- if ((isPinEnabled || isPasswordEnabled) && appLock == true) {
- result = await LocalAuthenticationService.instance
- .requestEnteAuthForLockScreen(context);
- await _configuration.removePinAndPassword();
- isPasswordEnabled = _configuration.isPasswordSet();
- isPinEnabled = _configuration.isPinSet();
- } else {
- result = await LocalAuthenticationService.instance
- .requestLocalAuthForLockScreen(
- context,
- !_configuration.shouldShowLockScreen(),
- S.of(context).authToChangeLockscreenSetting,
- S.of(context).lockScreenEnablePreSteps,
- );
- await _configuration.removePinAndPassword();
- isPasswordEnabled = _configuration.isPasswordSet();
- isPinEnabled = _configuration.isPinSet();
- }
- setState(() {
- if (result) {
- appLock = !appLock!;
- } else {
- appLock = appLock;
- }
- });
- }
+ // Future<void> _onToggleSwitch() async {
+ // bool result;
+ // if ((isPinEnabled || isPasswordEnabled) && appLock == true) {
+ // // result = await LocalAuthenticationService.instance
+ // // .requestEnteAuthForLockScreen(context);
+ // result = await requestAuthentication(
+ // context,
+ // S.of(context).authToChangeLockscreenSetting,
+ // );
+ // await _configuration.removePinAndPassword();
+ // isPasswordEnabled = _configuration.isPasswordSet();
+ // isPinEnabled = _configuration.isPinSet();
+ // } else {
+ // result = await LocalAuthenticationService.instance
+ // .requestLocalAuthForLockScreen(
+ // context,
+ // !_configuration.shouldShowLockScreen(),
+ // S.of(context).authToChangeLockscreenSetting,
+ // S.of(context).lockScreenEnablePreSteps,
+ // );
+ // await _configuration.removePinAndPassword();
+ // isPasswordEnabled = _configuration.isPasswordSet();
+ // isPinEnabled = _configuration.isPinSet();
+ // }
+ // setState(() {
+ // if (result) {
+ // appLock = !appLock!;
+ // } else {
+ // appLock = appLock;
+ // }
+ // });
+ // }
@override
Widget build(BuildContext context) {
@@ -143,7 +147,15 @@ class _LockScreenOptionState extends State<LockScreenOption> {
menuItemColor: colorTheme.fillFaint,
trailingWidget: ToggleSwitchWidget(
value: () => appLock!,
- onChanged: () => _onToggleSwitch(),
+ onChanged: () async {
+ setState(() {
+ _configuration.removePinAndPassword();
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled = _configuration.isPinSet();
+ appLock = !appLock!;
+ });
+ },
),
),
const Padding(
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
index 564b453144..468751fcb1 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
@@ -3,10 +3,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/dynamic_fab.dart";
-import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
-import "package:photos/ui/components/dialog_widget.dart";
-import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/components/text_input_widget.dart";
class LockScreenOptionConfirmPassword extends StatefulWidget {
@@ -26,6 +23,7 @@ class _LockScreenOptionConfirmPasswordState
final _confirmPasswordController = TextEditingController(text: null);
final Configuration _configuration = Configuration.instance;
final _focusNode = FocusNode();
+ final _isFormValid = ValueNotifier<bool>(false);
@override
void initState() {
@@ -38,46 +36,16 @@ class _LockScreenOptionConfirmPasswordState
@override
void dispose() {
- _focusNode.dispose();
super.dispose();
+ _focusNode.dispose();
}
Future<void> _confirmPasswordMatch() async {
if (widget.password == _confirmPasswordController.text) {
await _configuration.savePassword(_confirmPasswordController.text);
- await showDialogWidget(
- context: context,
- title: 'Password has been set',
- icon: Icons.lock,
- body: 'Hereafter password has been required while opening the app.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
+
Navigator.of(context).pop(true);
Navigator.of(context).pop(true);
- } else {
- await showDialogWidget(
- context: context,
- title: 'Password does not match',
- icon: Icons.lock,
- body: 'Please re-enter the password.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
}
_confirmPasswordController.clear();
}
@@ -110,13 +78,18 @@ class _LockScreenOptionConfirmPasswordState
),
),
),
- floatingActionButton: DynamicFAB(
- isKeypadOpen: isKeypadOpen,
- buttonText: S.of(context).confirm,
- isFormValid: _confirmPasswordController.text.isNotEmpty,
- onPressedFunction: () async {
- await _confirmPasswordMatch();
- FocusScope.of(context).unfocus();
+ floatingActionButton: ValueListenableBuilder<bool>(
+ valueListenable: _isFormValid,
+ builder: (context, isFormValid, child) {
+ return DynamicFAB(
+ isKeypadOpen: isKeypadOpen,
+ buttonText: S.of(context).confirm,
+ isFormValid: isFormValid,
+ onPressedFunction: () async {
+ await _confirmPasswordMatch();
+ FocusScope.of(context).unfocus();
+ },
+ );
},
),
floatingActionButtonLocation: fabLocation(),
@@ -173,6 +146,10 @@ class _LockScreenOptionConfirmPasswordState
textEditingController: _confirmPasswordController,
prefixIcon: Icons.lock_outline,
isPasswordInput: true,
+ onChange: (p0) {
+ _isFormValid.value =
+ _confirmPasswordController.text.isNotEmpty;
+ },
),
),
],
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_pin.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_pin.dart
index fe7f965932..4c386ecb29 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_pin.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_pin.dart
@@ -3,10 +3,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/dynamic_fab.dart";
-import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
-import "package:photos/ui/components/dialog_widget.dart";
-import "package:photos/ui/components/models/button_type.dart";
import "package:pinput/pin_put/pin_put.dart";
class LockScreenOptionConfirmPin extends StatefulWidget {
@@ -22,7 +19,6 @@ class _LockScreenOptionConfirmPinState
final _confirmPinController = TextEditingController(text: null);
final Configuration _configuration = Configuration.instance;
final _focusNode = FocusNode();
-
final _pinPutDecoration = BoxDecoration(
border: Border.all(color: const Color.fromRGBO(45, 194, 98, 1.0)),
borderRadius: BorderRadius.circular(15.0),
@@ -47,39 +43,9 @@ class _LockScreenOptionConfirmPinState
Future<void> _confirmPinMatch() async {
if (widget.pin == _confirmPinController.text) {
await _configuration.savePin(_confirmPinController.text);
- await showDialogWidget(
- context: context,
- title: 'Pin has been set',
- icon: Icons.lock,
- body: 'Hereafter pin has been required while opening the app.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
+
Navigator.of(context).pop(true);
Navigator.of(context).pop(true);
- } else {
- await showDialogWidget(
- context: context,
- title: 'Pin does not match',
- icon: Icons.lock,
- body: 'Please re-enter the pin.',
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: S.of(context).ok,
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
}
_confirmPinController.clear();
}
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
index cd3408476c..a1af2e87a0 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
@@ -22,6 +22,7 @@ class LockScreenOptionPassword extends StatefulWidget {
class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
final _passwordController = TextEditingController(text: null);
final _focusNode = FocusNode();
+ final _isFormValid = ValueNotifier<bool>(false);
@override
void initState() {
@@ -36,6 +37,7 @@ class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
void dispose() {
super.dispose();
_focusNode.dispose();
+ _isFormValid.dispose();
}
Future<bool> confirmPasswordAuth(String code) async {
@@ -91,13 +93,18 @@ class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
),
),
),
- floatingActionButton: DynamicFAB(
- isKeypadOpen: isKeypadOpen,
- buttonText: S.of(context).ok,
- isFormValid: _passwordController.text.isNotEmpty,
- onPressedFunction: () async {
- await _confirmPassword();
- FocusScope.of(context).unfocus();
+ floatingActionButton: ValueListenableBuilder<bool>(
+ valueListenable: _isFormValid,
+ builder: (context, isFormValid, child) {
+ return DynamicFAB(
+ isKeypadOpen: isKeypadOpen,
+ buttonText: S.of(context).ok,
+ isFormValid: isFormValid,
+ onPressedFunction: () async {
+ await _confirmPassword();
+ FocusScope.of(context).unfocus();
+ },
+ );
},
),
floatingActionButtonLocation: fabLocation(),
@@ -155,6 +162,9 @@ class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
textEditingController: _passwordController,
prefixIcon: Icons.lock_outline,
isPasswordInput: true,
+ onChange: (p0) {
+ _isFormValid.value = _passwordController.text.isNotEmpty;
+ },
),
),
],
diff --git a/mobile/lib/ui/settings/security_section_widget.dart b/mobile/lib/ui/settings/security_section_widget.dart
index 35e1d3fb72..3ddea3e47d 100644
--- a/mobile/lib/ui/settings/security_section_widget.dart
+++ b/mobile/lib/ui/settings/security_section_widget.dart
@@ -23,6 +23,7 @@ import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
import 'package:photos/ui/components/toggle_switch_widget.dart';
import "package:photos/ui/settings/TEMP/lock_screen_option.dart";
import 'package:photos/ui/settings/common_settings.dart';
+import "package:photos/utils/auth_util.dart";
import "package:photos/utils/crypto_util.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/navigation_util.dart";
@@ -145,13 +146,20 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
title: 'App lock',
),
onTap: () async {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOption();
- },
- ),
+ final bool result = await requestAuthentication(
+ context,
+ S.of(context).authToChangeLockscreenSetting,
);
+
+ if (result) {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const LockScreenOption();
+ },
+ ),
+ );
+ }
},
),
// MenuItemWidget(
diff --git a/mobile/lib/utils/auth_util.dart b/mobile/lib/utils/auth_util.dart
index 33e523a0c1..7d2b344b1c 100644
--- a/mobile/lib/utils/auth_util.dart
+++ b/mobile/lib/utils/auth_util.dart
@@ -3,36 +3,45 @@ import 'package:local_auth/local_auth.dart';
import 'package:local_auth_android/local_auth_android.dart';
import 'package:local_auth_ios/local_auth_ios.dart';
import 'package:logging/logging.dart';
+import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
+import "package:photos/services/local_authentication_service.dart";
Future<bool> requestAuthentication(BuildContext context, String reason) async {
Logger("AuthUtil").info("Requesting authentication");
await LocalAuthentication().stopAuthentication();
-
- return await LocalAuthentication().authenticate(
- localizedReason: reason,
- authMessages: [
- AndroidAuthMessages(
- biometricHint: S.of(context).androidBiometricHint,
- biometricNotRecognized: S.of(context).androidBiometricNotRecognized,
- biometricRequiredTitle: S.of(context).androidBiometricRequiredTitle,
- biometricSuccess: S.of(context).androidBiometricSuccess,
- cancelButton: S.of(context).androidCancelButton,
- deviceCredentialsRequiredTitle:
- S.of(context).androidDeviceCredentialsRequiredTitle,
- deviceCredentialsSetupDescription:
- S.of(context).androidDeviceCredentialsSetupDescription,
- goToSettingsButton: S.of(context).goToSettings,
- goToSettingsDescription: S.of(context).androidGoToSettingsDescription,
- signInTitle: S.of(context).androidSignInTitle,
- ),
- IOSAuthMessages(
- goToSettingsButton: S.of(context).goToSettings,
- goToSettingsDescription: S.of(context).goToSettings,
- lockOut: S.of(context).iOSLockOut,
- // cancelButton default value is "Ok"
- cancelButton: S.of(context).iOSOkButton,
- ),
- ],
- );
+ final Configuration configuration = Configuration.instance;
+ final String? savedPin = await configuration.loadSavedPin();
+ final String? savedPassword = await configuration.loadSavedPassword();
+ if (savedPassword != null || savedPin != null) {
+ return await LocalAuthenticationService.instance
+ .requestEnteAuthForLockScreen(context);
+ } else {
+ return await LocalAuthentication().authenticate(
+ localizedReason: reason,
+ authMessages: [
+ AndroidAuthMessages(
+ biometricHint: S.of(context).androidBiometricHint,
+ biometricNotRecognized: S.of(context).androidBiometricNotRecognized,
+ biometricRequiredTitle: S.of(context).androidBiometricRequiredTitle,
+ biometricSuccess: S.of(context).androidBiometricSuccess,
+ cancelButton: S.of(context).androidCancelButton,
+ deviceCredentialsRequiredTitle:
+ S.of(context).androidDeviceCredentialsRequiredTitle,
+ deviceCredentialsSetupDescription:
+ S.of(context).androidDeviceCredentialsSetupDescription,
+ goToSettingsButton: S.of(context).goToSettings,
+ goToSettingsDescription: S.of(context).androidGoToSettingsDescription,
+ signInTitle: S.of(context).androidSignInTitle,
+ ),
+ IOSAuthMessages(
+ goToSettingsButton: S.of(context).goToSettings,
+ goToSettingsDescription: S.of(context).goToSettings,
+ lockOut: S.of(context).iOSLockOut,
+ // cancelButton default value is "Ok"
+ cancelButton: S.of(context).iOSOkButton,
+ ),
+ ],
+ );
+ }
}