2022-10-04 13:12:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Yubico.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-04-03 12:05:37 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-12 16:46:43 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
|
|
|
import '../../app/message.dart';
|
|
|
|
import '../../app/models.dart';
|
|
|
|
import '../../app/views/app_page.dart';
|
2022-05-18 15:11:17 +03:00
|
|
|
import '../../app/views/graphics.dart';
|
2022-04-05 12:46:22 +03:00
|
|
|
import '../../app/views/message_page.dart';
|
2022-06-02 15:52:00 +03:00
|
|
|
import '../../widgets/list_title.dart';
|
2022-07-07 21:20:04 +03:00
|
|
|
import '../../widgets/menu_list_tile.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
import '../models.dart';
|
2022-04-04 12:15:38 +03:00
|
|
|
import '../state.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
import 'add_fingerprint_dialog.dart';
|
|
|
|
import 'delete_credential_dialog.dart';
|
|
|
|
import 'delete_fingerprint_dialog.dart';
|
|
|
|
import 'pin_dialog.dart';
|
|
|
|
import 'rename_fingerprint_dialog.dart';
|
|
|
|
import 'reset_dialog.dart';
|
|
|
|
|
|
|
|
class FidoUnlockedPage extends ConsumerWidget {
|
|
|
|
final DeviceNode node;
|
|
|
|
final FidoState state;
|
|
|
|
|
2022-05-12 10:56:55 +03:00
|
|
|
const FidoUnlockedPage(this.node, this.state, {super.key});
|
2022-04-03 12:05:37 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-05-24 17:41:57 +03:00
|
|
|
List<Widget> children = [];
|
|
|
|
if (state.credMgmt) {
|
|
|
|
final data = ref.watch(credentialProvider(node.path)).asData;
|
|
|
|
if (data == null) {
|
2022-09-12 17:14:58 +03:00
|
|
|
return _buildLoadingPage(context);
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
final creds = data.value;
|
|
|
|
if (creds.isNotEmpty) {
|
2022-09-12 16:46:43 +03:00
|
|
|
children.add(ListTitle(AppLocalizations.of(context)!.fido_credentials));
|
2022-05-24 17:41:57 +03:00
|
|
|
children.addAll(
|
|
|
|
creds.map(
|
|
|
|
(cred) => ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
|
|
child: const Icon(Icons.person),
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
cred.userName,
|
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
cred.rpId,
|
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
),
|
|
|
|
trailing: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-07-04 13:56:31 +03:00
|
|
|
showBlurDialog(
|
2022-05-24 17:41:57 +03:00
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
DeleteCredentialDialog(node.path, cred),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.delete_outline)),
|
|
|
|
],
|
|
|
|
),
|
2022-04-05 12:46:22 +03:00
|
|
|
),
|
2022-05-24 17:41:57 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 14:08:31 +03:00
|
|
|
int nFingerprints = 0;
|
2022-05-24 17:41:57 +03:00
|
|
|
if (state.bioEnroll != null) {
|
|
|
|
final data = ref.watch(fingerprintProvider(node.path)).asData;
|
|
|
|
if (data == null) {
|
2022-09-12 17:14:58 +03:00
|
|
|
return _buildLoadingPage(context);
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
final fingerprints = data.value;
|
|
|
|
if (fingerprints.isNotEmpty) {
|
2022-08-12 14:08:31 +03:00
|
|
|
nFingerprints = fingerprints.length;
|
2022-09-12 16:46:43 +03:00
|
|
|
children
|
|
|
|
.add(ListTitle(AppLocalizations.of(context)!.fido_fingerprints));
|
2022-05-24 17:41:57 +03:00
|
|
|
children.addAll(fingerprints.map((fp) => ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor: Theme.of(context).colorScheme.onSecondary,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
|
|
child: const Icon(Icons.fingerprint),
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
fp.label,
|
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
),
|
|
|
|
trailing: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-07-04 13:56:31 +03:00
|
|
|
showBlurDialog(
|
2022-05-24 17:41:57 +03:00
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
RenameFingerprintDialog(node.path, fp),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.edit_outlined)),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-07-04 13:56:31 +03:00
|
|
|
showBlurDialog(
|
2022-05-24 17:41:57 +03:00
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
DeleteFingerprintDialog(node.path, fp),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.delete_outline)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 12:46:22 +03:00
|
|
|
|
|
|
|
if (children.isNotEmpty) {
|
|
|
|
return AppPage(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_webauthn),
|
2022-08-12 14:08:31 +03:00
|
|
|
keyActions: _buildKeyActions(context, nFingerprints),
|
2022-06-02 15:52:00 +03:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, children: children),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:59:51 +03:00
|
|
|
if (state.bioEnroll != null) {
|
2022-04-05 12:46:22 +03:00
|
|
|
return MessagePage(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_webauthn),
|
2022-05-20 12:11:20 +03:00
|
|
|
graphic: noFingerprints,
|
2022-09-12 16:46:43 +03:00
|
|
|
header: AppLocalizations.of(context)!.fido_no_fingerprints,
|
|
|
|
message: AppLocalizations.of(context)!.fido_add_one_or_more,
|
2022-08-12 14:08:31 +03:00
|
|
|
keyActions: _buildKeyActions(context, 0),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessagePage(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_webauthn),
|
2022-06-07 13:10:01 +03:00
|
|
|
graphic: manageAccounts,
|
2022-09-12 16:46:43 +03:00
|
|
|
header: AppLocalizations.of(context)!.fido_no_discoverable_acc,
|
|
|
|
message: AppLocalizations.of(context)!.fido_register_as_a_key,
|
2022-08-12 14:08:31 +03:00
|
|
|
keyActions: _buildKeyActions(context, 0),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-12 17:14:58 +03:00
|
|
|
Widget _buildLoadingPage(BuildContext context) => AppPage(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_webauthn),
|
2022-05-24 17:41:57 +03:00
|
|
|
centered: true,
|
|
|
|
child: const CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
|
2022-08-12 14:08:31 +03:00
|
|
|
List<PopupMenuEntry> _buildKeyActions(
|
|
|
|
BuildContext context, int fingerprints) =>
|
|
|
|
[
|
2022-05-20 12:11:20 +03:00
|
|
|
if (state.bioEnroll != null)
|
2022-07-07 21:20:04 +03:00
|
|
|
buildMenuItem(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_add_fingerprint),
|
2022-07-07 21:20:04 +03:00
|
|
|
leading: const Icon(Icons.fingerprint),
|
2022-08-12 14:08:31 +03:00
|
|
|
trailing: '$fingerprints/5',
|
|
|
|
action: fingerprints < 5
|
|
|
|
? () {
|
|
|
|
showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AddFingerprintDialog(node.path),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
: null,
|
2022-04-05 12:46:22 +03:00
|
|
|
),
|
2022-07-07 21:20:04 +03:00
|
|
|
buildMenuItem(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_change_pin),
|
2022-07-07 21:20:04 +03:00
|
|
|
leading: const Icon(Icons.pin),
|
|
|
|
action: () {
|
|
|
|
showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => FidoPinDialog(node.path, state),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
buildMenuItem(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_reset_fido),
|
2022-07-07 21:20:04 +03:00
|
|
|
leading: const Icon(Icons.delete),
|
|
|
|
action: () {
|
|
|
|
showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ResetDialog(node),
|
|
|
|
);
|
2022-05-20 12:11:20 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
2022-04-03 12:05:37 +03:00
|
|
|
}
|