mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 18:22:39 +03:00
PIV: Add Default Key button to auth dialog.
This commit is contained in:
parent
0c37afc0e2
commit
c33a2e72bf
@ -37,12 +37,20 @@ class AuthenticationDialog extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AuthenticationDialogState extends ConsumerState<AuthenticationDialog> {
|
class _AuthenticationDialogState extends ConsumerState<AuthenticationDialog> {
|
||||||
String _managementKey = '';
|
bool _defaultKeyUsed = false;
|
||||||
bool _keyIsWrong = false;
|
bool _keyIsWrong = false;
|
||||||
|
final _keyController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_keyController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
final hasMetadata = widget.pivState.metadata != null;
|
||||||
final keyLen = (widget.pivState.metadata?.managementKeyMetadata.keyType ??
|
final keyLen = (widget.pivState.metadata?.managementKeyMetadata.keyType ??
|
||||||
ManagementKeyType.tdes)
|
ManagementKeyType.tdes)
|
||||||
.keyLength *
|
.keyLength *
|
||||||
@ -52,13 +60,13 @@ class _AuthenticationDialogState extends ConsumerState<AuthenticationDialog> {
|
|||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
key: keys.unlockButton,
|
key: keys.unlockButton,
|
||||||
onPressed: _managementKey.length == keyLen
|
onPressed: _keyController.text.length == keyLen
|
||||||
? () async {
|
? () async {
|
||||||
final navigator = Navigator.of(context);
|
final navigator = Navigator.of(context);
|
||||||
try {
|
try {
|
||||||
final status = await ref
|
final status = await ref
|
||||||
.read(pivStateProvider(widget.devicePath).notifier)
|
.read(pivStateProvider(widget.devicePath).notifier)
|
||||||
.authenticate(_managementKey);
|
.authenticate(_keyController.text);
|
||||||
if (status) {
|
if (status) {
|
||||||
navigator.pop(true);
|
navigator.pop(true);
|
||||||
} else {
|
} else {
|
||||||
@ -88,24 +96,44 @@ class _AuthenticationDialogState extends ConsumerState<AuthenticationDialog> {
|
|||||||
TextField(
|
TextField(
|
||||||
key: keys.managementKeyField,
|
key: keys.managementKeyField,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
maxLength: keyLen,
|
|
||||||
autofillHints: const [AutofillHints.password],
|
autofillHints: const [AutofillHints.password],
|
||||||
|
controller: _keyController,
|
||||||
inputFormatters: [
|
inputFormatters: [
|
||||||
FilteringTextInputFormatter.allow(
|
FilteringTextInputFormatter.allow(
|
||||||
RegExp('[a-f0-9]', caseSensitive: false))
|
RegExp('[a-f0-9]', caseSensitive: false))
|
||||||
],
|
],
|
||||||
|
readOnly: _defaultKeyUsed,
|
||||||
|
maxLength: !_defaultKeyUsed ? keyLen : null,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
labelText: l10n.s_management_key,
|
labelText: l10n.s_management_key,
|
||||||
prefixIcon: const Icon(Icons.key_outlined),
|
prefixIcon: const Icon(Icons.key_outlined),
|
||||||
errorText: _keyIsWrong ? l10n.l_wrong_key : null,
|
errorText: _keyIsWrong ? l10n.l_wrong_key : null,
|
||||||
errorMaxLines: 3,
|
errorMaxLines: 3,
|
||||||
|
helperText: _defaultKeyUsed ? l10n.l_default_key_used : null,
|
||||||
|
suffixIcon: hasMetadata
|
||||||
|
? null
|
||||||
|
: IconButton(
|
||||||
|
icon: Icon(_defaultKeyUsed
|
||||||
|
? Icons.auto_awesome
|
||||||
|
: Icons.auto_awesome_outlined),
|
||||||
|
tooltip: l10n.s_use_default,
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_defaultKeyUsed = !_defaultKeyUsed;
|
||||||
|
if (_defaultKeyUsed) {
|
||||||
|
_keyController.text = defaultManagementKey;
|
||||||
|
} else {
|
||||||
|
_keyController.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_keyIsWrong = false;
|
_keyIsWrong = false;
|
||||||
_managementKey = value;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user