Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/src/utils/solid_file_operations_download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ class SolidFileDownloadOperations {

if (!context.mounted) return;

await getKeyFromUserIfRequired(
if (!await getKeyFromUserIfRequired(
context,
const Text('Please enter your security key to download the file'),
);
)) {
return;
}

if (!context.mounted) return;

Expand Down Expand Up @@ -308,10 +310,12 @@ class SolidFileDownloadOperations {

// Get security key if required.

await getKeyFromUserIfRequired(
if (!await getKeyFromUserIfRequired(
context,
const Text('Please enter your security key to download the files'),
);
)) {
return;
}

if (!context.mounted) return;

Expand Down
6 changes: 4 additions & 2 deletions lib/src/utils/solid_file_operations_print.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ class SolidFilePrintOperations {
try {
if (!context.mounted) return;

await getKeyFromUserIfRequired(
if (!await getKeyFromUserIfRequired(
context,
const Text('Please enter your security key to print the file'),
);
)) {
return;
}

if (!context.mounted) return;

Expand Down
6 changes: 4 additions & 2 deletions lib/src/utils/solid_file_operations_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ class SolidFileUploadOperations {

// Ensure the security key is available before writing encrypted data.

await getKeyFromUserIfRequired(
if (!await getKeyFromUserIfRequired(
context,
const Text('Please enter your security key to upload the file'),
);
)) {
return;
}

if (!context.mounted) return;

Expand Down
11 changes: 7 additions & 4 deletions lib/src/utils/solid_pod_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ Future<bool> loginIfRequired(BuildContext context) async {
/// Ask for the security key from the user if the security key is not available
/// or cannot be verfied using the verification key stored in PODs.

Future<void> getKeyFromUserIfRequired(
Future<bool> getKeyFromUserIfRequired(
BuildContext context,
Widget child,
) async {
if (await KeyManager.hasSecurityKey()) {
return;
return true;
} else {
final verificationKey = await KeyManager.getVerificationKey();
// Get the webId to display in the security key prompt.
Expand Down Expand Up @@ -148,13 +148,13 @@ Future<void> getKeyFromUserIfRequired(
submitFunc: (formDataMap) async {
await KeyManager.setSecurityKey(formDataMap[inputKey].toString());
debugPrint('Security key saved');
if (context.mounted) Navigator.pop(context);
if (context.mounted) Navigator.pop(context, true);
},
child: child,
);

if (context.mounted) {
await Navigator.push(
final result = await Navigator.push<bool>(
context,
MaterialPageRoute(builder: (context) => securityKeyInput),
);
Expand All @@ -163,6 +163,9 @@ Future<void> getKeyFromUserIfRequired(
// changed after the user submitted (or dismissed) the key prompt.

await securityKeyNotifier.refreshStatus();

return result ?? false;
}
return false;
}
}
8 changes: 1 addition & 7 deletions lib/src/widgets/security_key_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,7 @@ class _SecurityKeyUIState extends State<SecurityKeyUI> {
child: SecurityKeyButtons(
canSubmit: _canSubmit,
onSubmit: () async => _submit(context),
onCancel: () {
if (widget.displayMode == SecurityKeyDisplayMode.dialog) {
Navigator.pop(context);
} else {
pushReplacement(context, widget.child);
}
},
onCancel: () => Navigator.pop(context, false),
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/solid_login_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SolidLoginActions {
// Ensure the security key has been fetched once logged in.

if (isLoggedIn) {
await getKeyFromUserIfRequired(context, childWidget);
if (!await getKeyFromUserIfRequired(context, childWidget)) return;
if (!context.mounted) return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/widgets/solid_login_auth_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class SolidLoginAuthHandler {
}

if (!context.mounted) return false;
await getKeyFromUserIfRequired(context, childWidget);
if (!await getKeyFromUserIfRequired(context, childWidget)) return false;
if (!context.mounted) return true;
await pushReplacement(context, childWidget);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ class SolidLoginAuthHandler {
}

if (!context.mounted) return false;
await getKeyFromUserIfRequired(context, childWidget);
if (!await getKeyFromUserIfRequired(context, childWidget)) return false;
if (!context.mounted) return true;
await pushReplacement(context, childWidget);
}
Expand Down
Loading