瀏覽代碼

Add the ability to add and edit issuers

vishnukvmd 2 年之前
父節點
當前提交
94debda2c7
共有 3 個文件被更改,包括 36 次插入12 次删除
  1. 4 3
      lib/l10n/arb/app_en.arb
  2. 4 4
      lib/models/code.dart
  3. 28 5
      lib/onboarding/view/setup_enter_secret_key_page.dart

+ 4 - 3
lib/l10n/arb/app_en.arb

@@ -11,12 +11,13 @@
   "importScanQrCode": "Scan a QR Code",
   "importScanQrCode": "Scan a QR Code",
   "importEnterSetupKey": "Enter a setup key",
   "importEnterSetupKey": "Enter a setup key",
   "importAccountPageTitle": "Enter account details",
   "importAccountPageTitle": "Enter account details",
-  "accountNameHint": "Account name",
-  "accountKeyHint" : "Your key",
+  "codeIssuerHint": "Issuer",
+  "codeSecretKeyHint" : "Secret Key",
+  "codeAccountHint": "Account (you@domain.com)",
   "accountKeyType": "Type of key",
   "accountKeyType": "Type of key",
   "timeBasedKeyType": "Time based (TOTP)",
   "timeBasedKeyType": "Time based (TOTP)",
   "counterBasedKeyType": "Counter based (HOTP)",
   "counterBasedKeyType": "Counter based (HOTP)",
-  "importAddAction": "Add",
+  "saveAction": "Save",
 
 
   "existingUser": "Existing User",
   "existingUser": "Existing User",
   "newUser" : "New to ente"
   "newUser" : "New to ente"

+ 4 - 4
lib/models/code.dart

@@ -27,21 +27,21 @@ class Code {
     this.id,
     this.id,
   });
   });
 
 
-  static Code fromAccountAndSecret(String account, String secret) {
+  static Code fromAccountAndSecret(String account, String issuer, String secret) {
     return Code(
     return Code(
       account,
       account,
-      "",
+      issuer,
       defaultDigits,
       defaultDigits,
       defaultPeriod,
       defaultPeriod,
       secret,
       secret,
       Algorithm.sha1,
       Algorithm.sha1,
       Type.totp,
       Type.totp,
       "otpauth://totp/" +
       "otpauth://totp/" +
-          account +
+          issuer +
           ":" +
           ":" +
           account +
           account +
           "?algorithm=SHA1&digits=6&issuer=" +
           "?algorithm=SHA1&digits=6&issuer=" +
-          account +
+          issuer +
           "period=30&secret=" +
           "period=30&secret=" +
           secret,
           secret,
     );
     );

+ 28 - 5
lib/onboarding/view/setup_enter_secret_key_page.dart

@@ -16,14 +16,20 @@ class SetupEnterSecretKeyPage extends StatefulWidget {
 }
 }
 
 
 class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
 class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
+  late TextEditingController _issuerController;
   late TextEditingController _accountController;
   late TextEditingController _accountController;
   late TextEditingController _secretController;
   late TextEditingController _secretController;
 
 
   @override
   @override
   void initState() {
   void initState() {
+    _issuerController = TextEditingController(
+      text: widget.code != null
+          ? Uri.decodeFull(widget.code!.issuer).trim()
+          : null,
+    );
     _accountController = TextEditingController(
     _accountController = TextEditingController(
       text: widget.code != null
       text: widget.code != null
-          ? Uri.decodeFull(widget.code!.account).toString()
+          ? Uri.decodeFull(widget.code!.account).trim()
           : null,
           : null,
     );
     );
     _secretController = TextEditingController(
     _secretController = TextEditingController(
@@ -54,9 +60,9 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
                     return null;
                     return null;
                   },
                   },
                   decoration: InputDecoration(
                   decoration: InputDecoration(
-                    hintText: l10n.accountNameHint,
+                    hintText: l10n.codeIssuerHint,
                   ),
                   ),
-                  controller: _accountController,
+                  controller: _issuerController,
                   autofocus: true,
                   autofocus: true,
                 ),
                 ),
                 const SizedBox(
                 const SizedBox(
@@ -71,10 +77,26 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
                     return null;
                     return null;
                   },
                   },
                   decoration: InputDecoration(
                   decoration: InputDecoration(
-                    hintText: l10n.accountKeyHint,
+                    hintText: l10n.codeSecretKeyHint,
                   ),
                   ),
                   controller: _secretController,
                   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(
                 const SizedBox(
                   height: 40,
                   height: 40,
                 ),
                 ),
@@ -90,6 +112,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
                       try {
                       try {
                         final code = Code.fromAccountAndSecret(
                         final code = Code.fromAccountAndSecret(
                           _accountController.text.trim(),
                           _accountController.text.trim(),
+                          _issuerController.text.trim(),
                           _secretController.text.trim(),
                           _secretController.text.trim(),
                         );
                         );
                         // Verify the validity of the code
                         // Verify the validity of the code
@@ -107,7 +130,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
                         horizontal: 16.0,
                         horizontal: 16.0,
                         vertical: 4,
                         vertical: 4,
                       ),
                       ),
-                      child: Text(l10n.importAddAction),
+                      child: Text(l10n.saveAction),
                     ),
                     ),
                   ),
                   ),
                 )
                 )