mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 16:32:01 +03:00
Add feature per OTP configuration type.
This commit is contained in:
parent
2b8c5259ba
commit
868c96b72b
@ -22,5 +22,9 @@ final actionsSwap = actions.feature('swap');
|
||||
|
||||
final slots = otp.feature('slots');
|
||||
|
||||
final slotsConfigure = slots.feature('configure');
|
||||
final slotsConfigureChalResp = slots.feature('configureChalResp');
|
||||
final slotsConfigureHotp = slots.feature('configureHotp');
|
||||
final slotsConfigureStatic = slots.feature('configureSlots');
|
||||
final slotsConfigureYubiOtp = slots.feature('configureYubiOtp');
|
||||
|
||||
final slotsDelete = slots.feature('delete');
|
||||
|
@ -39,8 +39,6 @@ enum SlotId {
|
||||
SlotId.values.firstWhere((e) => e.id == value);
|
||||
}
|
||||
|
||||
enum SlotConfigurationType { yubiotp, static, hotp, chalresp }
|
||||
|
||||
@freezed
|
||||
class OtpState with _$OtpState {
|
||||
const OtpState._();
|
||||
|
@ -33,10 +33,20 @@ import 'configure_static_dialog.dart';
|
||||
import 'configure_yubiotp_dialog.dart';
|
||||
import 'delete_slot_dialog.dart';
|
||||
|
||||
class ConfigureIntent extends Intent {
|
||||
const ConfigureIntent({required this.configurationType});
|
||||
class ConfigureChalRespIntent extends Intent {
|
||||
const ConfigureChalRespIntent();
|
||||
}
|
||||
|
||||
final SlotConfigurationType configurationType;
|
||||
class ConfigureHotpIntent extends Intent {
|
||||
const ConfigureHotpIntent();
|
||||
}
|
||||
|
||||
class ConfigureStaticIntent extends Intent {
|
||||
const ConfigureStaticIntent();
|
||||
}
|
||||
|
||||
class ConfigureYubiOtpIntent extends Intent {
|
||||
const ConfigureYubiOtpIntent();
|
||||
}
|
||||
|
||||
Widget registerOtpActions(
|
||||
@ -49,28 +59,36 @@ Widget registerOtpActions(
|
||||
final hasFeature = ref.watch(featureProvider);
|
||||
return Actions(
|
||||
actions: {
|
||||
if (hasFeature(features.slotsConfigure))
|
||||
ConfigureIntent:
|
||||
CallbackAction<ConfigureIntent>(onInvoke: (intent) async {
|
||||
if (hasFeature(features.slotsConfigureChalResp))
|
||||
ConfigureChalRespIntent:
|
||||
CallbackAction<ConfigureChalRespIntent>(onInvoke: (intent) async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
final configurationType = intent.configurationType;
|
||||
|
||||
switch (configurationType) {
|
||||
case SlotConfigurationType.chalresp:
|
||||
await withContext((context) async {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
ConfigureChalrespDialog(devicePath, otpSlot));
|
||||
});
|
||||
case SlotConfigurationType.hotp:
|
||||
return null;
|
||||
}),
|
||||
if (hasFeature(features.slotsConfigureHotp))
|
||||
ConfigureHotpIntent:
|
||||
CallbackAction<ConfigureHotpIntent>(onInvoke: (intent) async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
|
||||
await withContext((context) async {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
ConfigureHotpDialog(devicePath, otpSlot));
|
||||
builder: (context) => ConfigureHotpDialog(devicePath, otpSlot));
|
||||
});
|
||||
case SlotConfigurationType.static:
|
||||
return null;
|
||||
}),
|
||||
if (hasFeature(features.slotsConfigureStatic))
|
||||
ConfigureStaticIntent:
|
||||
CallbackAction<ConfigureStaticIntent>(onInvoke: (intent) async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
|
||||
final keyboardLayouts = await ref
|
||||
.read(otpStateProvider(devicePath).notifier)
|
||||
.getKeyboardLayouts();
|
||||
@ -80,17 +98,19 @@ Widget registerOtpActions(
|
||||
builder: (context) => ConfigureStaticDialog(
|
||||
devicePath, otpSlot, keyboardLayouts));
|
||||
});
|
||||
case SlotConfigurationType.yubiotp:
|
||||
return null;
|
||||
}),
|
||||
if (hasFeature(features.slotsConfigureYubiOtp))
|
||||
ConfigureYubiOtpIntent:
|
||||
CallbackAction<ConfigureYubiOtpIntent>(onInvoke: (intent) async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
|
||||
await withContext((context) async {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
ConfigureYubiOtpDialog(devicePath, otpSlot));
|
||||
});
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}),
|
||||
if (hasFeature(features.slotsDelete))
|
||||
@ -115,36 +135,33 @@ List<ActionItem> buildSlotActions(bool isConfigured, AppLocalizations l10n) {
|
||||
return [
|
||||
ActionItem(
|
||||
key: keys.configureYubiOtp,
|
||||
feature: features.slotsConfigure,
|
||||
feature: features.slotsConfigureYubiOtp,
|
||||
icon: const Icon(Icons.shuffle_outlined),
|
||||
title: l10n.s_yubiotp,
|
||||
subtitle: l10n.l_yubiotp_desc,
|
||||
intent: const ConfigureIntent(
|
||||
configurationType: SlotConfigurationType.yubiotp)),
|
||||
intent: const ConfigureYubiOtpIntent(),
|
||||
),
|
||||
ActionItem(
|
||||
key: keys.configureChalResp,
|
||||
feature: features.slotsConfigure,
|
||||
feature: features.slotsConfigureChalResp,
|
||||
icon: const Icon(Icons.key_outlined),
|
||||
title: l10n.s_challenge_response,
|
||||
subtitle: l10n.l_challenge_response_desc,
|
||||
intent: const ConfigureIntent(
|
||||
configurationType: SlotConfigurationType.chalresp)),
|
||||
intent: const ConfigureChalRespIntent()),
|
||||
ActionItem(
|
||||
key: keys.configureStatic,
|
||||
feature: features.slotsConfigure,
|
||||
feature: features.slotsConfigureStatic,
|
||||
icon: const Icon(Icons.password_outlined),
|
||||
title: l10n.s_static_password,
|
||||
subtitle: l10n.l_static_password_desc,
|
||||
intent: const ConfigureIntent(
|
||||
configurationType: SlotConfigurationType.static)),
|
||||
intent: const ConfigureStaticIntent()),
|
||||
ActionItem(
|
||||
key: keys.configureHotp,
|
||||
feature: features.slotsConfigure,
|
||||
feature: features.slotsConfigureHotp,
|
||||
icon: const Icon(Icons.tag_outlined),
|
||||
title: l10n.s_hotp,
|
||||
subtitle: l10n.l_hotp_desc,
|
||||
intent: const ConfigureIntent(
|
||||
configurationType: SlotConfigurationType.hotp)),
|
||||
intent: const ConfigureHotpIntent()),
|
||||
ActionItem(
|
||||
key: keys.deleteAction,
|
||||
feature: features.slotsDelete,
|
||||
|
Loading…
Reference in New Issue
Block a user