]> git.proxmox.com Git - flutter/proxmox_login_manager.git/blobdiff - lib/proxmox_login_selector.dart
optionally save passwords with biometric storage
[flutter/proxmox_login_manager.git] / lib / proxmox_login_selector.dart
index 52655231b0fa813e3ddceade733eb033a3ed6511..e1af146caa85560815765e80c842a2581d6055f8 100644 (file)
@@ -6,6 +6,7 @@ import 'package:proxmox_login_manager/proxmox_login_model.dart';
 import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart'
     as proxclient;
 import 'package:proxmox_login_manager/extension.dart';
+import 'package:proxmox_login_manager/proxmox_password_store.dart';
 
 typedef OnLoginCallback = Function(proxclient.ProxmoxApiClient client);
 
@@ -30,6 +31,7 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
   Widget build(BuildContext context) {
     return SafeArea(
       child: Scaffold(
+        backgroundColor: Theme.of(context).colorScheme.background,
         appBar: AppBar(
           title: Column(
             crossAxisAlignment: CrossAxisAlignment.start,
@@ -130,20 +132,44 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                     ),
                   ),
                 ),
-                ...logins.where((b) => !b.activeSession).map((l) => ListTile(
-                      title: Text(l.fullHostname),
-                      subtitle: Text(l.fullUsername),
+                ...logins.where((b) => !b.activeSession).map((login) =>
+                    ListTile(
+                      title: Text(login.fullHostname),
+                      subtitle: Text(login.fullUsername),
                       trailing: Icon(Icons.navigate_next),
                       leading: PopupMenuButton(
                           itemBuilder: (context) => [
+                                if (login.passwordSaved ?? false)
+                                  PopupMenuItem(
+                                    child: ListTile(
+                                      dense: true,
+                                      leading: Icon(Icons.key_off),
+                                      title: Text('Delete Password'),
+                                      onTap: () async {
+                                        await deletePassword(login.identifier!);
+
+                                        await snapshot.data!
+                                            .rebuild((b) => b
+                                              ..logins.rebuildWhere(
+                                                  (m) => m == login,
+                                                  (b) =>
+                                                      b..passwordSaved = false))
+                                            .saveToDisk();
+                                        refreshFromStorage();
+                                        Navigator.of(context).pop();
+                                      },
+                                    ),
+                                  ),
                                 PopupMenuItem(
                                   child: ListTile(
                                     dense: true,
                                     leading: Icon(Icons.delete),
                                     title: Text('Delete'),
                                     onTap: () async {
+                                      await deletePassword(login.identifier!);
                                       await snapshot.data!
-                                          .rebuild((b) => b.logins.remove(l))
+                                          .rebuild(
+                                              (b) => b.logins.remove(login))
                                           .saveToDisk();
                                       refreshFromStorage();
                                       Navigator.of(context).pop();
@@ -151,7 +177,7 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                                   ),
                                 ),
                               ]),
-                      onTap: () => _login(user: l),
+                      onTap: () => _login(user: login),
                     ))
               ]);
               return ListView(
@@ -168,11 +194,20 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
   }
 
   Future<void> _login({ProxmoxLoginModel? user, bool isCreate = false}) async {
+    String? password;
+    String ticket = user?.ticket ?? '';
+    bool passwordSaved = user != null && (user.passwordSaved ?? false);
+
+    if (ticket == '' && passwordSaved) {
+      password = await getPassword(user.identifier!);
+    }
+
     final client = await Navigator.of(context).push(MaterialPageRoute(
         builder: (context) => ProxmoxLoginPage(
               userModel: user,
               isCreate: isCreate,
               ticket: user?.ticket,
+              password: password,
             )));
     refreshFromStorage();
     if (client != null) {