Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

[photos] Passkey changes

Neeraj Guptab100392d7ed6
diff --git a/mobile/lib/core/errors.dart b/mobile/lib/core/errors.dart
index d39f6f027f..f1c7c24b3c 100644
--- a/mobile/lib/core/errors.dart
+++ b/mobile/lib/core/errors.dart
@@ -81,3 +81,7 @@ class SrpSetupNotCompleteError extends Error {}
class SharingNotPermittedForFreeAccountsError extends Error {}
class NoMediaLocationAccessError extends Error {}
+
+class PassKeySessionNotVerifiedError extends Error {}
+
+class PassKeySessionExpiredError extends Error {}
diff --git a/mobile/lib/generated/intl/messages_en.dart b/mobile/lib/generated/intl/messages_en.dart
index 9e6e86c00b..c910297559 100644
--- a/mobile/lib/generated/intl/messages_en.dart
+++ b/mobile/lib/generated/intl/messages_en.dart
@@ -418,6 +418,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Check for updates"),
"checkInboxAndSpamFolder": MessageLookupByLibrary.simpleMessage(
"Please check your inbox (and spam) to complete verification"),
+ "checkStatus": MessageLookupByLibrary.simpleMessage("Check status"),
"checking": MessageLookupByLibrary.simpleMessage("Checking..."),
"claimFreeStorage":
MessageLookupByLibrary.simpleMessage("Claim free storage"),
@@ -906,6 +907,10 @@ class MessageLookup extends MessageLookupByLibrary {
"lockscreen": MessageLookupByLibrary.simpleMessage("Lockscreen"),
"logInLabel": MessageLookupByLibrary.simpleMessage("Log in"),
"loggingOut": MessageLookupByLibrary.simpleMessage("Logging out..."),
+ "loginSessionExpired":
+ MessageLookupByLibrary.simpleMessage("Session expired"),
+ "loginSessionExpiredDetails": MessageLookupByLibrary.simpleMessage(
+ "Your session has expired. Please login again."),
"loginTerms": MessageLookupByLibrary.simpleMessage(
"By clicking log in, I agree to the <u-terms>terms of service</u-terms> and <u-policy>privacy policy</u-policy>"),
"logout": MessageLookupByLibrary.simpleMessage("Logout"),
@@ -1018,6 +1023,8 @@ class MessageLookup extends MessageLookupByLibrary {
"pairWithPin": MessageLookupByLibrary.simpleMessage("Pair with PIN"),
"pairingComplete":
MessageLookupByLibrary.simpleMessage("Pairing complete"),
+ "passKeyPendingVerification": MessageLookupByLibrary.simpleMessage(
+ "Verification is still pending"),
"passkey": MessageLookupByLibrary.simpleMessage("Passkey"),
"passkeyAuthTitle":
MessageLookupByLibrary.simpleMessage("Passkey verification"),
diff --git a/mobile/lib/generated/intl/messages_pt.dart b/mobile/lib/generated/intl/messages_pt.dart
index e9dfccdfc4..025bf911fd 100644
--- a/mobile/lib/generated/intl/messages_pt.dart
+++ b/mobile/lib/generated/intl/messages_pt.dart
@@ -783,6 +783,8 @@ class MessageLookup extends MessageLookupByLibrary {
"freeUpAmount": m29,
"freeUpDeviceSpace": MessageLookupByLibrary.simpleMessage(
"Liberar espaço no dispositivo"),
+ "freeUpDeviceSpaceDesc": MessageLookupByLibrary.simpleMessage(
+ "Economize espaço no seu dispositivo limpando arquivos que já foram salvos em backup."),
"freeUpSpace": MessageLookupByLibrary.simpleMessage("Liberar espaço"),
"freeUpSpaceSaving": m30,
"galleryMemoryLimitInfo": MessageLookupByLibrary.simpleMessage(
@@ -909,7 +911,7 @@ class MessageLookup extends MessageLookupByLibrary {
"loadMessage7": MessageLookupByLibrary.simpleMessage(
"Nossos aplicativos móveis são executados em segundo plano para criptografar e fazer backup de quaisquer novas fotos que você clique"),
"loadMessage8": MessageLookupByLibrary.simpleMessage(
- "web.ente.io tem um upload rápido"),
+ "web.ente.io tem um envio mais rápido"),
"loadMessage9": MessageLookupByLibrary.simpleMessage(
"Nós usamos Xchacha20Poly1305 para criptografar seus dados com segurança"),
"loadingExifData":
@@ -1194,6 +1196,8 @@ class MessageLookup extends MessageLookupByLibrary {
"remove": MessageLookupByLibrary.simpleMessage("Remover"),
"removeDuplicates":
MessageLookupByLibrary.simpleMessage("Excluir duplicados"),
+ "removeDuplicatesDesc": MessageLookupByLibrary.simpleMessage(
+ "Revise e remova arquivos que sejam duplicatas exatas."),
"removeFromAlbum":
MessageLookupByLibrary.simpleMessage("Remover do álbum"),
"removeFromAlbumTitle":
@@ -1588,6 +1592,10 @@ class MessageLookup extends MessageLookupByLibrary {
"viewAll": MessageLookupByLibrary.simpleMessage("Ver tudo"),
"viewAllExifData":
MessageLookupByLibrary.simpleMessage("Ver todos os dados EXIF"),
+ "viewLargeFiles":
+ MessageLookupByLibrary.simpleMessage("Arquivos grandes"),
+ "viewLargeFilesDesc": MessageLookupByLibrary.simpleMessage(
+ "Ver arquivos que estão consumindo mais espaço de armazenamento"),
"viewLogs": MessageLookupByLibrary.simpleMessage("Ver logs"),
"viewRecoveryKey":
MessageLookupByLibrary.simpleMessage("Ver chave de recuperação"),
diff --git a/mobile/lib/generated/l10n.dart b/mobile/lib/generated/l10n.dart
index fd50133186..cfd0b186b7 100644
--- a/mobile/lib/generated/l10n.dart
+++ b/mobile/lib/generated/l10n.dart
@@ -3162,6 +3162,16 @@ class S {
);
}
+ /// `Check status`
+ String get checkStatus {
+ return Intl.message(
+ 'Check status',
+ name: 'checkStatus',
+ desc: '',
+ args: [],
+ );
+ }
+
/// `Checking...`
String get checking {
return Intl.message(
@@ -8408,6 +8418,36 @@ class S {
);
}
+ /// `Verification is still pending`
+ String get passKeyPendingVerification {
+ return Intl.message(
+ 'Verification is still pending',
+ name: 'passKeyPendingVerification',
+ desc: '',
+ args: [],
+ );
+ }
+
+ /// `Session expired`
+ String get loginSessionExpired {
+ return Intl.message(
+ 'Session expired',
+ name: 'loginSessionExpired',
+ desc: '',
+ args: [],
+ );
+ }
+
+ /// `Your session has expired. Please login again.`
+ String get loginSessionExpiredDetails {
+ return Intl.message(
+ 'Your session has expired. Please login again.',
+ name: 'loginSessionExpiredDetails',
+ desc: '',
+ args: [],
+ );
+ }
+
/// `Verify passkey`
String get verifyPasskey {
return Intl.message(
diff --git a/mobile/lib/l10n/intl_en.arb b/mobile/lib/l10n/intl_en.arb
index 0cabea3f05..d8a863dc92 100644
--- a/mobile/lib/l10n/intl_en.arb
+++ b/mobile/lib/l10n/intl_en.arb
@@ -451,6 +451,7 @@
"privacy": "Privacy",
"terms": "Terms",
"checkForUpdates": "Check for updates",
+ "checkStatus": "Check status",
"checking": "Checking...",
"youAreOnTheLatestVersion": "You are on the latest version",
"account": "Account",
@@ -1198,6 +1199,9 @@
"waitingForVerification": "Waiting for verification...",
"passkey": "Passkey",
"passkeyAuthTitle": "Passkey verification",
+ "passKeyPendingVerification": "Verification is still pending",
+ "loginSessionExpired" : "Session expired",
+ "loginSessionExpiredDetails": "Your session has expired. Please login again.",
"verifyPasskey": "Verify passkey",
"playOnTv": "Play album on TV",
"pair": "Pair",
diff --git a/mobile/lib/services/user_service.dart b/mobile/lib/services/user_service.dart
index 44e098567c..1a58a3328a 100644
--- a/mobile/lib/services/user_service.dart
+++ b/mobile/lib/services/user_service.dart
@@ -308,6 +308,31 @@ class UserService {
}
}
+ Future<dynamic> getTokenForPasskeySession(String sessionID) async {
+ try {
+ final response = await _dio.get(
+ "${_config.getHttpEndpoint()}/users/two-factor/passkeys/get-token",
+ queryParameters: {
+ "sessionID": sessionID,
+ },
+ );
+ return response.data;
+ } on DioError catch (e) {
+ if (e.response != null) {
+ if (e.response!.statusCode == 404 || e.response!.statusCode == 410) {
+ throw PassKeySessionExpiredError();
+ }
+ if (e.response!.statusCode == 400) {
+ throw PassKeySessionNotVerifiedError();
+ }
+ }
+ rethrow;
+ } catch (e, s) {
+ _logger.severe("unexpected error", e, s);
+ rethrow;
+ }
+ }
+
Future<void> onPassKeyVerified(BuildContext context, Map response) async {
final userPassword = Configuration.instance.getVolatilePassword();
if (userPassword == null) throw Exception("volatile password is null");
diff --git a/mobile/lib/ui/account/passkey_page.dart b/mobile/lib/ui/account/passkey_page.dart
index bd852de781..25c529ffd1 100644
--- a/mobile/lib/ui/account/passkey_page.dart
+++ b/mobile/lib/ui/account/passkey_page.dart
@@ -3,13 +3,15 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
-import "package:photos/generated/l10n.dart";
+import "package:photos/core/errors.dart";
+import "package:photos/l10n/l10n.dart";
import "package:photos/models/account/two_factor.dart";
import 'package:photos/services/user_service.dart';
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/utils/dialog_util.dart";
-import 'package:uni_links/uni_links.dart';
+import "package:photos/utils/toast_util.dart";
+import "package:uni_links/uni_links.dart";
import 'package:url_launcher/url_launcher_string.dart';
class PasskeyPage extends StatefulWidget {
@@ -17,8 +19,8 @@ class PasskeyPage extends StatefulWidget {
const PasskeyPage(
this.sessionID, {
- Key? key,
- }) : super(key: key);
+ super.key,
+ });
@override
State<PasskeyPage> createState() => _PasskeyPageState();
@@ -50,6 +52,29 @@ class _PasskeyPageState extends State<PasskeyPage> {
);
}
+ Future<void> checkStatus() async {
+ late dynamic response;
+ try {
+ response = await UserService.instance
+ .getTokenForPasskeySession(widget.sessionID);
+ } on PassKeySessionNotVerifiedError catch (e) {
+ showToast(context, context.l10n.passKeyPendingVerification);
+ } on PassKeySessionExpiredError catch (e) {
+ await showErrorDialog(
+ context,
+ context.l10n.loginSessionExpired,
+ context.l10n.loginSessionExpiredDetails,
+ );
+ Navigator.of(context).pop();
+ return;
+ } catch (e, s) {
+ _logger.severe("failed to check status", e, s);
+ showGenericErrorDialog(context: context, error: e).ignore();
+ return;
+ }
+ await UserService.instance.onPassKeyVerified(context, response);
+ }
+
Future<void> _handleDeeplink(String? link) async {
if (!context.mounted ||
Configuration.instance.hasConfiguredAccount() ||
@@ -61,6 +86,11 @@ class _PasskeyPageState extends State<PasskeyPage> {
}
try {
if (mounted && link.toLowerCase().startsWith("ente://passkey")) {
+ if (Configuration.instance.isLoggedIn()) {
+ _logger.info('ignored deeplink: already configured');
+ showToast(context, 'Account is already configured.');
+ return;
+ }
final String? uri = Uri.parse(link).queryParameters['response'];
String base64String = uri!.toString();
while (base64String.length % 4 != 0) {
@@ -91,10 +121,11 @@ class _PasskeyPageState extends State<PasskeyPage> {
@override
Widget build(BuildContext context) {
+ final l10n = context.l10n;
return Scaffold(
appBar: AppBar(
title: Text(
- S.of(context).passkeyAuthTitle,
+ l10n.passkeyAuthTitle,
),
),
body: _getBody(),
@@ -109,7 +140,7 @@ class _PasskeyPageState extends State<PasskeyPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
- S.of(context).waitingForVerification,
+ context.l10n.waitingForVerification,
style: const TextStyle(
height: 1.4,
fontSize: 16,
@@ -118,9 +149,16 @@ class _PasskeyPageState extends State<PasskeyPage> {
const SizedBox(height: 16),
ButtonWidget(
buttonType: ButtonType.primary,
- labelText: S.of(context).verifyPasskey,
+ labelText: context.l10n.tryAgain,
onTap: () => launchPasskey(),
),
+ const SizedBox(height: 16),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ labelText: context.l10n.checkStatus,
+ onTap: checkStatus,
+ shouldSurfaceExecutionStates: true,
+ ),
const Padding(padding: EdgeInsets.all(30)),
GestureDetector(
behavior: HitTestBehavior.opaque,
@@ -135,7 +173,7 @@ class _PasskeyPageState extends State<PasskeyPage> {
padding: const EdgeInsets.all(10),
child: Center(
child: Text(
- S.of(context).recoverAccount,
+ context.l10n.recoverAccount,
style: const TextStyle(
decoration: TextDecoration.underline,
fontSize: 12,