Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Refactor + use better variable names

ashilkn6ab5015b9db4
diff --git a/mobile/lib/services/local_authentication_service.dart b/mobile/lib/services/local_authentication_service.dart
index 4f2c6916bc..a989da5124 100644
--- a/mobile/lib/services/local_authentication_service.dart
+++ b/mobile/lib/services/local_authentication_service.dart
@@ -39,7 +39,7 @@ class LocalAuthenticationService {
BuildContext context,
String? savedPin,
String? savedPassword, {
- bool isLockscreenAuth = false,
+ bool isOnOpeningApp = false,
}) async {
if (savedPassword != null) {
final result = await Navigator.of(context).push(
@@ -47,7 +47,7 @@ class LocalAuthenticationService {
builder: (BuildContext context) {
return LockScreenPassword(
isAuthenticating: true,
- isLockscreenAuth: isLockscreenAuth,
+ isOnOpeningApp: isOnOpeningApp,
authPass: savedPassword,
);
},
@@ -63,7 +63,7 @@ class LocalAuthenticationService {
builder: (BuildContext context) {
return LockScreenPin(
isAuthenticating: true,
- isLockscreenAuth: isLockscreenAuth,
+ isOnOpeningApp: isOnOpeningApp,
authPin: savedPin,
);
},
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_password.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_password.dart
index eba1d6f338..0b7d9b9452 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_password.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_password.dart
@@ -17,14 +17,13 @@ class LockScreenPassword extends StatefulWidget {
const LockScreenPassword({
super.key,
this.isAuthenticating = false,
- this.isLockscreenAuth = false,
+ this.isOnOpeningApp = false,
this.authPass,
});
- /// If [isLockscreenAuth] is true then we are authenticating the user at Lock screen
- /// If [isAuthenticating] is true then we are authenticating the user at Setting screen
+ //Is false when setting a new password
final bool isAuthenticating;
- final bool isLockscreenAuth;
+ final bool isOnOpeningApp;
final String? authPass;
@override
State<LockScreenPassword> createState() => _LockScreenPasswordState();
@@ -38,8 +37,7 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
final _submitNotifier = ValueNotifier(false);
int invalidAttemptsCount = 0;
- final LockScreenSettings _lockscreenSetting = LockScreenSettings.instance;
- late String enteredHashedPassword;
+ final _lockscreenSetting = LockScreenSettings.instance;
@override
void initState() {
super.initState();
@@ -57,57 +55,6 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
_isFormValid.dispose();
}
- Future<bool> confirmPasswordAuth(String code) async {
- final Uint8List? salt = await _lockscreenSetting.getSalt();
- final hash = cryptoPwHash({
- "password": utf8.encode(code),
- "salt": salt,
- "opsLimit": Sodium.cryptoPwhashOpslimitInteractive,
- "memLimit": Sodium.cryptoPwhashMemlimitInteractive,
- });
-
- enteredHashedPassword = base64Encode(hash);
- if (widget.authPass == enteredHashedPassword) {
- await _lockscreenSetting.setInvalidAttemptCount(0);
-
- widget.isLockscreenAuth
- ? Navigator.of(context).pop(true)
- : Navigator.of(context).pushReplacement(
- MaterialPageRoute(
- builder: (context) => const LockScreenOptions(),
- ),
- );
- return true;
- } else {
- if (widget.isLockscreenAuth) {
- invalidAttemptsCount++;
- if (invalidAttemptsCount > 4) {
- await _lockscreenSetting.setInvalidAttemptCount(invalidAttemptsCount);
- Navigator.of(context).pop(false);
- }
- }
-
- await HapticFeedback.vibrate();
- throw Exception("Incorrect password");
- }
- }
-
- Future<void> _confirmPassword() async {
- if (widget.isAuthenticating) {
- await confirmPasswordAuth(_passwordController.text);
- return;
- } else {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) => LockScreenConfirmPassword(
- password: _passwordController.text,
- ),
- ),
- );
- _passwordController.clear();
- }
- }
-
@override
Widget build(BuildContext context) {
final colorTheme = getEnteColorScheme(context);
@@ -218,4 +165,54 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
),
);
}
+
+ Future<bool> _confirmPasswordAuth(String inputtedPassword) async {
+ final Uint8List? salt = await _lockscreenSetting.getSalt();
+ final hash = cryptoPwHash({
+ "password": utf8.encode(inputtedPassword),
+ "salt": salt,
+ "opsLimit": Sodium.cryptoPwhashOpslimitInteractive,
+ "memLimit": Sodium.cryptoPwhashMemlimitInteractive,
+ });
+
+ if (widget.authPass == base64Encode(hash)) {
+ await _lockscreenSetting.setInvalidAttemptCount(0);
+
+ widget.isOnOpeningApp
+ ? Navigator.of(context).pop(true)
+ : Navigator.of(context).pushReplacement(
+ MaterialPageRoute(
+ builder: (context) => const LockScreenOptions(),
+ ),
+ );
+ return true;
+ } else {
+ if (widget.isOnOpeningApp) {
+ invalidAttemptsCount++;
+ if (invalidAttemptsCount > 4) {
+ await _lockscreenSetting.setInvalidAttemptCount(invalidAttemptsCount);
+ Navigator.of(context).pop(false);
+ }
+ }
+
+ await HapticFeedback.vibrate();
+ throw Exception("Incorrect password");
+ }
+ }
+
+ Future<void> _confirmPassword() async {
+ if (widget.isAuthenticating) {
+ await _confirmPasswordAuth(_passwordController.text);
+ return;
+ } else {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) => LockScreenConfirmPassword(
+ password: _passwordController.text,
+ ),
+ ),
+ );
+ _passwordController.clear();
+ }
+ }
}
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
index 6b36b9b623..2cea93e7fc 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
@@ -18,14 +18,13 @@ class LockScreenPin extends StatefulWidget {
const LockScreenPin({
super.key,
this.isAuthenticating = false,
- this.isLockscreenAuth = false,
+ this.isOnOpeningApp = false,
this.authPin,
});
- /// If [isLockscreenAuth] is true then we are authenticating the user at the Lock screen
- /// If [isAuthenticating] is true then we are authenticating the user at the Setting screen
+ //Is false when setting a new password
final bool isAuthenticating;
- final bool isLockscreenAuth;
+ final bool isOnOpeningApp;
final String? authPin;
@override
State<LockScreenPin> createState() => _LockScreenPinState();
@@ -35,7 +34,6 @@ class _LockScreenPinState extends State<LockScreenPin> {
final _pinController = TextEditingController(text: null);
final LockScreenSettings _lockscreenSetting = LockScreenSettings.instance;
- late String enteredHashedPin;
bool isPinValid = false;
int invalidAttemptsCount = 0;
@@ -51,19 +49,6 @@ class _LockScreenPinState extends State<LockScreenPin> {
_pinController.dispose();
}
- void _onKeyTap(String number) {
- _pinController.text += number;
- return;
- }
-
- void _onBackspace() {
- if (_pinController.text.isNotEmpty) {
- _pinController.text =
- _pinController.text.substring(0, _pinController.text.length - 1);
- }
- return;
- }
-
Future<bool> confirmPinAuth(String code) async {
final Uint8List? salt = await _lockscreenSetting.getSalt();
final hash = cryptoPwHash({
@@ -73,11 +58,10 @@ class _LockScreenPinState extends State<LockScreenPin> {
"memLimit": Sodium.cryptoPwhashMemlimitInteractive,
});
- enteredHashedPin = base64Encode(hash);
- if (widget.authPin == enteredHashedPin) {
+ if (widget.authPin == base64Encode(hash)) {
invalidAttemptsCount = 0;
await _lockscreenSetting.setInvalidAttemptCount(0);
- widget.isLockscreenAuth
+ widget.isOnOpeningApp
? Navigator.of(context).pop(true)
: Navigator.of(context).pushReplacement(
MaterialPageRoute(
@@ -96,7 +80,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
isPinValid = false;
});
- if (widget.isLockscreenAuth) {
+ if (widget.isOnOpeningApp) {
invalidAttemptsCount++;
if (invalidAttemptsCount > 4) {
await _lockscreenSetting.setInvalidAttemptCount(invalidAttemptsCount);
diff --git a/mobile/lib/ui/tools/lock_screen.dart b/mobile/lib/ui/tools/lock_screen.dart
index 752996a8d9..ba12a9f3ab 100644
--- a/mobile/lib/ui/tools/lock_screen.dart
+++ b/mobile/lib/ui/tools/lock_screen.dart
@@ -296,7 +296,7 @@ class _LockScreenState extends State<LockScreen>
: await requestAuthentication(
context,
context.l10n.authToViewYourMemories,
- isLockscreenAuth: true,
+ isOnOpeningApp: true,
);
_logger.finest("LockScreen Result $result $id");
_isShowingLockScreen = false;
diff --git a/mobile/lib/utils/auth_util.dart b/mobile/lib/utils/auth_util.dart
index dca030d4aa..8f7c1f0c6e 100644
--- a/mobile/lib/utils/auth_util.dart
+++ b/mobile/lib/utils/auth_util.dart
@@ -10,7 +10,7 @@ import "package:photos/utils/lock_screen_settings.dart";
Future<bool> requestAuthentication(
BuildContext context,
String reason, {
- bool isLockscreenAuth = false,
+ bool isOnOpeningApp = false,
}) async {
Logger("AuthUtil").info("Requesting authentication");
await LocalAuthentication().stopAuthentication();
@@ -24,7 +24,7 @@ Future<bool> requestAuthentication(
context,
savedPin,
savedPassword,
- isLockscreenAuth: isLockscreenAuth,
+ isOnOpeningApp: isOnOpeningApp,
);
} else {
return await LocalAuthentication().authenticate(