[Kimchi-devel] [PATCH 6/6] UI: Redirect user to console page after logging

Aline Manera alinefm at linux.vnet.ibm.com
Fri May 2 00:49:25 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

vnc_auto.html and spice.html are now protected through Kimchi
authentication.
When a non-authenticated user tries to access those URLs he/she will be
redirected to login page. After it, he/she will get the console page
according to cookies console_type and console_uri (set by nginx)

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 ui/js/src/kimchi.login_window.js |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/ui/js/src/kimchi.login_window.js b/ui/js/src/kimchi.login_window.js
index 44e5617..fc5af36 100644
--- a/ui/js/src/kimchi.login_window.js
+++ b/ui/js/src/kimchi.login_window.js
@@ -82,7 +82,29 @@ kimchi.login_main = function() {
 
         kimchi.login(settings, function() {
             var pAjax = kimchi.previousAjax;
-            if (pAjax && true === pAjax['resend']) {
+            var consoleURL = kimchi.cookie.get("console_uri");
+            var consoleType = kimchi.cookie.get("console_type");
+            if (consoleURL) {
+                if (consoleType === 'vnc') {
+                    var proxy_port = /.*port=(.*?)(&|$)/g.exec(consoleURL);
+                    var http_port = /.*kimchi=(.*?)(&|$)/g.exec(consoleURL);
+
+                    var port = proxy_port ? proxy_port[1] : location.port;
+                    var kimchi_port = http_port ? http_port[1] : location.port;
+
+                    if (proxy_port && !http_port) {
+                        consoleURL += "&kimchi=" + kimchi_port;
+                    }
+
+                    url = location.protocol + "//" + location.hostname;
+                    url += ":" + port
+                    consoleURL = url + consoleURL
+                }
+                kimchi.cookie.remove("console_uri");
+                kimchi.cookie.remove("console_type");
+                window.location.replace(consoleURL)
+            }
+            else if (pAjax && true === pAjax['resend']) {
                 pAjax['error'] = pAjax['originalError'];
                 $.ajax(pAjax);
                 kimchi.previousAjax = null;
-- 
1.7.10.4




More information about the Kimchi-devel mailing list