2022-03-17 22:10:10 +03:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-09-12 16:46:43 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-03-17 22:10:10 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-03-18 17:56:07 +03:00
|
|
|
import 'package:logging/logging.dart';
|
2022-05-03 12:24:25 +03:00
|
|
|
import 'package:yubico_authenticator/app/logging.dart';
|
2022-03-17 22:10:10 +03:00
|
|
|
|
2022-03-25 17:43:32 +03:00
|
|
|
import '../../app/message.dart';
|
2022-03-18 18:10:05 +03:00
|
|
|
import '../../core/models.dart';
|
2022-06-13 17:45:26 +03:00
|
|
|
import '../../desktop/models.dart';
|
2022-03-31 12:50:40 +03:00
|
|
|
import '../../widgets/responsive_dialog.dart';
|
2022-03-17 22:10:10 +03:00
|
|
|
import '../state.dart';
|
|
|
|
import '../../fido/models.dart';
|
|
|
|
import '../../app/models.dart';
|
|
|
|
|
2022-03-18 17:56:07 +03:00
|
|
|
final _log = Logger('fido.views.reset_dialog');
|
|
|
|
|
2022-03-17 22:10:10 +03:00
|
|
|
class ResetDialog extends ConsumerStatefulWidget {
|
|
|
|
final DeviceNode node;
|
2022-05-12 10:56:55 +03:00
|
|
|
const ResetDialog(this.node, {super.key});
|
2022-03-17 22:10:10 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _ResetDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ResetDialogState extends ConsumerState<ResetDialog> {
|
|
|
|
StreamSubscription<InteractionEvent>? _subscription;
|
|
|
|
InteractionEvent? _interaction;
|
|
|
|
|
|
|
|
String _getMessage() {
|
|
|
|
final nfc = widget.node.transport == Transport.nfc;
|
|
|
|
switch (_interaction) {
|
|
|
|
case InteractionEvent.remove:
|
|
|
|
return nfc
|
2022-09-12 16:46:43 +03:00
|
|
|
? AppLocalizations.of(context)!.fido_remove_from_reader
|
|
|
|
: AppLocalizations.of(context)!.fido_unplug_yubikey;
|
2022-03-17 22:10:10 +03:00
|
|
|
case InteractionEvent.insert:
|
|
|
|
return nfc
|
2022-09-12 16:46:43 +03:00
|
|
|
? AppLocalizations.of(context)!.fido_place_back_on_reader
|
|
|
|
: AppLocalizations.of(context)!.fido_reinsert_yubikey;
|
2022-03-17 22:10:10 +03:00
|
|
|
case InteractionEvent.touch:
|
2022-09-12 16:46:43 +03:00
|
|
|
return AppLocalizations.of(context)!.fido_touch_yubikey;
|
2022-03-17 22:10:10 +03:00
|
|
|
case null:
|
2022-09-12 16:46:43 +03:00
|
|
|
return AppLocalizations.of(context)!.fido_press_reset;
|
2022-03-17 22:10:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ResponsiveDialog(
|
2022-09-12 16:46:43 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.fido_factory_reset),
|
2022-03-17 22:10:10 +03:00
|
|
|
onCancel: () {
|
|
|
|
_subscription?.cancel();
|
|
|
|
},
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: _subscription == null
|
|
|
|
? () async {
|
|
|
|
_subscription = ref
|
|
|
|
.read(fidoStateProvider(widget.node.path).notifier)
|
|
|
|
.reset()
|
2022-03-18 15:54:50 +03:00
|
|
|
.listen((event) {
|
|
|
|
setState(() {
|
|
|
|
_interaction = event;
|
|
|
|
});
|
|
|
|
}, onDone: () {
|
|
|
|
_subscription = null;
|
|
|
|
Navigator.of(context).pop();
|
2022-09-12 16:46:43 +03:00
|
|
|
showMessage(context,
|
|
|
|
AppLocalizations.of(context)!.fido_fido_app_reset);
|
2022-03-18 17:56:07 +03:00
|
|
|
}, onError: (e) {
|
2022-05-03 12:24:25 +03:00
|
|
|
_log.error('Error performing FIDO reset', e);
|
2022-03-18 17:56:07 +03:00
|
|
|
Navigator.of(context).pop();
|
2022-06-13 17:45:26 +03:00
|
|
|
final String errorMessage;
|
|
|
|
// TODO: Make this cleaner than importing desktop specific RpcError.
|
|
|
|
if (e is RpcError) {
|
|
|
|
errorMessage = e.message;
|
|
|
|
} else {
|
|
|
|
errorMessage = e.toString();
|
|
|
|
}
|
|
|
|
showMessage(
|
|
|
|
context,
|
2022-09-12 16:46:43 +03:00
|
|
|
'${AppLocalizations.of(context)!.fido_error_reset}: $errorMessage',
|
2022-06-13 17:45:26 +03:00
|
|
|
duration: const Duration(seconds: 4),
|
|
|
|
);
|
2022-03-18 15:54:50 +03:00
|
|
|
});
|
2022-03-17 22:10:10 +03:00
|
|
|
}
|
|
|
|
: null,
|
2022-09-12 16:46:43 +03:00
|
|
|
child: Text(AppLocalizations.of(context)!.fido_reset),
|
2022-03-17 22:10:10 +03:00
|
|
|
),
|
|
|
|
],
|
2022-09-07 11:25:22 +03:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-12 16:46:43 +03:00
|
|
|
Text(AppLocalizations.of(context)!
|
|
|
|
.fido_warning_will_delete_accounts),
|
2022-09-07 11:25:22 +03:00
|
|
|
Text(
|
2022-09-12 16:46:43 +03:00
|
|
|
AppLocalizations.of(context)!.fido_warning_disable_these_creds,
|
2022-09-07 11:25:22 +03:00
|
|
|
style: Theme.of(context).textTheme.bodyText1,
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: Text(_getMessage(),
|
|
|
|
style: Theme.of(context).textTheme.titleLarge),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
.map((e) => Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: e,
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
),
|
2022-05-12 09:34:51 +03:00
|
|
|
),
|
2022-03-17 22:10:10 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|