[Spice-devel] [spice-html5][PATCH v2 09/13] Prompt password in spice_auto.html

Cédric Bosdonnat cbosdonnat at suse.com
Thu Feb 14 09:44:52 UTC 2019


In case the user didn't provide any password, we want to prompt him for
it. Try once and if we get an permission denied error, then ask the
password and retry to connect.
---
 spice_auto.html | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/spice_auto.html b/spice_auto.html
index 71c6556..d3d136f 100644
--- a/spice_auto.html
+++ b/spice_auto.html
@@ -69,9 +69,13 @@
             function spice_error(e)
             {
                 disconnect();
+                if (e !== undefined && e.message === "Permission denied.") {
+                  var pass = prompt("Password");
+                  connect(pass);
+                }
             }
 
-            function connect()
+            function connect(password)
             {
                 var host, port, password, scheme = "ws://", uri;
 
@@ -102,7 +106,9 @@
                     spice_set_cookie('token', token, 1)
                 }
 
-                password = spice_query_var('password', '');
+                if (password === undefined) {
+                    password = spice_query_var('password', '');
+                }
                 var path = spice_query_var('path', 'websockify');
 
                 if ((!host) || (!port)) {
@@ -184,7 +190,7 @@
             });
             */
 
-            connect();
+            connect(undefined);
         </script>
 
     </head>
-- 
2.19.2



More information about the Spice-devel mailing list