diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 4a368f9b8..86043f446 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -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" diff --git a/lib/models/code.dart b/lib/models/code.dart index 444ef7846..baf11c9f8 100644 --- a/lib/models/code.dart +++ b/lib/models/code.dart @@ -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, ); diff --git a/lib/onboarding/view/setup_enter_secret_key_page.dart b/lib/onboarding/view/setup_enter_secret_key_page.dart index a98330054..4a7e7a572 100644 --- a/lib/onboarding/view/setup_enter_secret_key_page.dart +++ b/lib/onboarding/view/setup_enter_secret_key_page.dart @@ -16,14 +16,20 @@ class SetupEnterSecretKeyPage extends StatefulWidget { } class _SetupEnterSecretKeyPageState extends State { + 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 { 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 { 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 { 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 { horizontal: 16.0, vertical: 4, ), - child: Text(l10n.importAddAction), + child: Text(l10n.saveAction), ), ), )