mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 16:32:01 +03:00
Improve add OATH account.
- Add padding to match Period with Digits. - Validate secret length on submit.
This commit is contained in:
parent
40335e66da
commit
6963b69c10
@ -31,6 +31,7 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
HashAlgorithm _hashAlgorithm = defaultHashAlgorithm;
|
HashAlgorithm _hashAlgorithm = defaultHashAlgorithm;
|
||||||
int _period = defaultPeriod;
|
int _period = defaultPeriod;
|
||||||
int _digits = defaultDigits;
|
int _digits = defaultDigits;
|
||||||
|
bool _validateSecretLength = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -43,9 +44,8 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
final issuerRemaining = remaining.first;
|
final issuerRemaining = remaining.first;
|
||||||
final nameRemaining = remaining.second;
|
final nameRemaining = remaining.second;
|
||||||
|
|
||||||
final secretValid = _secret.length * 5 % 8 < 5;
|
final secretLengthValid = _secret.length * 5 % 8 < 5;
|
||||||
final isValid =
|
final isValid = _account.isNotEmpty && _secret.isNotEmpty && _period > 0;
|
||||||
_account.isNotEmpty && _secret.isNotEmpty && secretValid && _period > 0;
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
@ -86,10 +86,13 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
],
|
],
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Secret key',
|
labelText: 'Secret key',
|
||||||
errorText: secretValid ? null : 'Invalid value'),
|
errorText: _validateSecretLength && !secretLengthValid
|
||||||
|
? 'Invalid length'
|
||||||
|
: null),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_secret = value.replaceAll(' ', '');
|
_secret = value.replaceAll(' ', '');
|
||||||
|
_validateSecretLength = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -148,7 +151,7 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: DropdownButtonFormField<HashAlgorithm>(
|
child: DropdownButtonFormField<HashAlgorithm>(
|
||||||
decoration:
|
decoration:
|
||||||
const InputDecoration(label: Text('Algorithm')),
|
const InputDecoration(labelText: 'Algorithm'),
|
||||||
value: _hashAlgorithm,
|
value: _hashAlgorithm,
|
||||||
items: HashAlgorithm.values
|
items: HashAlgorithm.values
|
||||||
.map((e) => DropdownMenuItem(
|
.map((e) => DropdownMenuItem(
|
||||||
@ -178,7 +181,10 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
FilteringTextInputFormatter.digitsOnly,
|
FilteringTextInputFormatter.digitsOnly,
|
||||||
],
|
],
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
label: const Text('Period'),
|
contentPadding:
|
||||||
|
// Manual alignment to match digits-dropdown.
|
||||||
|
const EdgeInsets.fromLTRB(0, 12, 0, 15),
|
||||||
|
labelText: 'Period',
|
||||||
errorText: _period > 0
|
errorText: _period > 0
|
||||||
? null
|
? null
|
||||||
: 'Must be a positive number',
|
: 'Must be a positive number',
|
||||||
@ -196,8 +202,7 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: DropdownButtonFormField<int>(
|
child: DropdownButtonFormField<int>(
|
||||||
decoration:
|
decoration: const InputDecoration(labelText: 'Digits'),
|
||||||
const InputDecoration(label: Text('Digits')),
|
|
||||||
value: _digits,
|
value: _digits,
|
||||||
items: [6, 7, 8]
|
items: [6, 7, 8]
|
||||||
.map((e) => DropdownMenuItem(
|
.map((e) => DropdownMenuItem(
|
||||||
@ -223,6 +228,7 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: isValid
|
onPressed: isValid
|
||||||
? () {
|
? () {
|
||||||
|
if (secretLengthValid) {
|
||||||
widget.onSubmit(
|
widget.onSubmit(
|
||||||
CredentialData(
|
CredentialData(
|
||||||
issuer: _issuer.isEmpty ? null : _issuer,
|
issuer: _issuer.isEmpty ? null : _issuer,
|
||||||
@ -235,6 +241,11 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
|||||||
),
|
),
|
||||||
_touch,
|
_touch,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_validateSecretLength = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
child: const Text('Add account'),
|
child: const Text('Add account'),
|
||||||
|
Loading…
Reference in New Issue
Block a user