Require confirmation during Save if Secret Key
This commit is contained in:
parent
92bfa153f1
commit
573b3a321d
2 changed files with 45 additions and 26 deletions
|
@ -331,5 +331,6 @@
|
||||||
"offlineModeWarning": "You have chosen to proceed without backups. Please take manual backups to make sure your codes are safe.",
|
"offlineModeWarning": "You have chosen to proceed without backups. Please take manual backups to make sure your codes are safe.",
|
||||||
"showLargeIcons": "Show large icons",
|
"showLargeIcons": "Show large icons",
|
||||||
"shouldHideCode": "Hide codes",
|
"shouldHideCode": "Hide codes",
|
||||||
"focusOnSearchBar": "Focus search on app start"
|
"focusOnSearchBar": "Focus search on app start",
|
||||||
|
"confirmUpdatingkey": "Are you sure you want to update the secret key?"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import "package:ente_auth/l10n/l10n.dart";
|
import "package:ente_auth/l10n/l10n.dart";
|
||||||
import 'package:ente_auth/models/code.dart';
|
import 'package:ente_auth/models/code.dart';
|
||||||
|
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
|
||||||
|
import 'package:ente_auth/ui/components/models/button_result.dart';
|
||||||
import 'package:ente_auth/utils/dialog_util.dart';
|
import 'package:ente_auth/utils/dialog_util.dart';
|
||||||
import 'package:ente_auth/utils/totp_util.dart';
|
import 'package:ente_auth/utils/totp_util.dart';
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
|
@ -10,7 +12,8 @@ class SetupEnterSecretKeyPage extends StatefulWidget {
|
||||||
SetupEnterSecretKeyPage({this.code, Key? key}) : super(key: key);
|
SetupEnterSecretKeyPage({this.code, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SetupEnterSecretKeyPage> createState() => _SetupEnterSecretKeyPageState();
|
State<SetupEnterSecretKeyPage> createState() =>
|
||||||
|
_SetupEnterSecretKeyPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
|
@ -25,7 +28,8 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
text: widget.code != null ? safeDecode(widget.code!.issuer).trim() : null,
|
text: widget.code != null ? safeDecode(widget.code!.issuer).trim() : null,
|
||||||
);
|
);
|
||||||
_accountController = TextEditingController(
|
_accountController = TextEditingController(
|
||||||
text: widget.code != null ? safeDecode(widget.code!.account).trim() : null,
|
text:
|
||||||
|
widget.code != null ? safeDecode(widget.code!.account).trim() : null,
|
||||||
);
|
);
|
||||||
_secretController = TextEditingController(
|
_secretController = TextEditingController(
|
||||||
text: widget.code != null ? widget.code!.secret : null,
|
text: widget.code != null ? widget.code!.secret : null,
|
||||||
|
@ -110,7 +114,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if ((_accountController.text.trim().isEmpty &&
|
if ((_accountController.text.trim().isEmpty &&
|
||||||
_issuerController.text.trim().isEmpty) ||
|
_issuerController.text.trim().isEmpty) ||
|
||||||
_secretController.text.trim().isEmpty) {
|
_secretController.text.trim().isEmpty) {
|
||||||
|
@ -118,15 +122,28 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
if (_secretController.text.trim().isEmpty) {
|
if (_secretController.text.trim().isEmpty) {
|
||||||
message = context.l10n.secretCanNotBeEmpty;
|
message = context.l10n.secretCanNotBeEmpty;
|
||||||
} else {
|
} else {
|
||||||
message = context.l10n.bothIssuerAndAccountCanNotBeEmpty;
|
message =
|
||||||
|
context.l10n.bothIssuerAndAccountCanNotBeEmpty;
|
||||||
}
|
}
|
||||||
_showIncorrectDetailsDialog(context, message: message);
|
_showIncorrectDetailsDialog(context, message: message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ButtonResult? result = await showChoiceActionSheet(
|
||||||
|
context,
|
||||||
|
title: context.l10n.warning,
|
||||||
|
body: context.l10n.confirmUpdatingkey,
|
||||||
|
firstButtonLabel: context.l10n.yes,
|
||||||
|
secondButtonAction: ButtonAction.cancel,
|
||||||
|
secondButtonLabel: context.l10n.cancel,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == null) return;
|
||||||
|
if (result.action == ButtonAction.first) {
|
||||||
try {
|
try {
|
||||||
final account = _accountController.text.trim();
|
final account = _accountController.text.trim();
|
||||||
final issuer = _issuerController.text.trim();
|
final issuer = _issuerController.text.trim();
|
||||||
final secret = _secretController.text.trim().replaceAll(' ', '');
|
final secret =
|
||||||
|
_secretController.text.trim().replaceAll(' ', '');
|
||||||
final Code newCode = widget.code == null
|
final Code newCode = widget.code == null
|
||||||
? Code.fromAccountAndSecret(
|
? Code.fromAccountAndSecret(
|
||||||
account,
|
account,
|
||||||
|
@ -144,6 +161,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_showIncorrectDetailsDialog(context);
|
_showIncorrectDetailsDialog(context);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
|
@ -153,7 +171,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||||
child: Text(l10n.saveAction),
|
child: Text(l10n.saveAction),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Reference in a new issue