Add the ability to add and edit issuers
This commit is contained in:
parent
c9f37b4f5a
commit
94debda2c7
3 changed files with 36 additions and 12 deletions
|
@ -11,12 +11,13 @@
|
|||
"importScanQrCode": "Scan a QR Code",
|
||||
"importEnterSetupKey": "Enter a setup key",
|
||||
"importAccountPageTitle": "Enter account details",
|
||||
"accountNameHint": "Account name",
|
||||
"accountKeyHint" : "Your key",
|
||||
"codeIssuerHint": "Issuer",
|
||||
"codeSecretKeyHint" : "Secret Key",
|
||||
"codeAccountHint": "Account (you@domain.com)",
|
||||
"accountKeyType": "Type of key",
|
||||
"timeBasedKeyType": "Time based (TOTP)",
|
||||
"counterBasedKeyType": "Counter based (HOTP)",
|
||||
"importAddAction": "Add",
|
||||
"saveAction": "Save",
|
||||
|
||||
"existingUser": "Existing User",
|
||||
"newUser" : "New to ente"
|
||||
|
|
|
@ -27,21 +27,21 @@ class Code {
|
|||
this.id,
|
||||
});
|
||||
|
||||
static Code fromAccountAndSecret(String account, String secret) {
|
||||
static Code fromAccountAndSecret(String account, String issuer, String secret) {
|
||||
return Code(
|
||||
account,
|
||||
"",
|
||||
issuer,
|
||||
defaultDigits,
|
||||
defaultPeriod,
|
||||
secret,
|
||||
Algorithm.sha1,
|
||||
Type.totp,
|
||||
"otpauth://totp/" +
|
||||
account +
|
||||
issuer +
|
||||
":" +
|
||||
account +
|
||||
"?algorithm=SHA1&digits=6&issuer=" +
|
||||
account +
|
||||
issuer +
|
||||
"period=30&secret=" +
|
||||
secret,
|
||||
);
|
||||
|
|
|
@ -16,14 +16,20 @@ class SetupEnterSecretKeyPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
||||
late TextEditingController _issuerController;
|
||||
late TextEditingController _accountController;
|
||||
late TextEditingController _secretController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_issuerController = TextEditingController(
|
||||
text: widget.code != null
|
||||
? Uri.decodeFull(widget.code!.issuer).trim()
|
||||
: null,
|
||||
);
|
||||
_accountController = TextEditingController(
|
||||
text: widget.code != null
|
||||
? Uri.decodeFull(widget.code!.account).toString()
|
||||
? Uri.decodeFull(widget.code!.account).trim()
|
||||
: null,
|
||||
);
|
||||
_secretController = TextEditingController(
|
||||
|
@ -54,9 +60,9 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
|||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.accountNameHint,
|
||||
hintText: l10n.codeIssuerHint,
|
||||
),
|
||||
controller: _accountController,
|
||||
controller: _issuerController,
|
||||
autofocus: true,
|
||||
),
|
||||
const SizedBox(
|
||||
|
@ -71,10 +77,26 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
|||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.accountKeyHint,
|
||||
hintText: l10n.codeSecretKeyHint,
|
||||
),
|
||||
controller: _secretController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
TextFormField(
|
||||
// The validator receives the text that the user has entered.
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please enter some text";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.codeAccountHint,
|
||||
),
|
||||
controller: _accountController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 40,
|
||||
),
|
||||
|
@ -90,6 +112,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
|||
try {
|
||||
final code = Code.fromAccountAndSecret(
|
||||
_accountController.text.trim(),
|
||||
_issuerController.text.trim(),
|
||||
_secretController.text.trim(),
|
||||
);
|
||||
// Verify the validity of the code
|
||||
|
@ -107,7 +130,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
|||
horizontal: 16.0,
|
||||
vertical: 4,
|
||||
),
|
||||
child: Text(l10n.importAddAction),
|
||||
child: Text(l10n.saveAction),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue