[pve-devel] r5966 - pve-manager/pve2/www/new

svn-commits at proxmox.com svn-commits at proxmox.com
Thu May 12 08:59:47 CEST 2011


Author: dietmar
Date: 2011-05-12 08:59:47 +0200 (Thu, 12 May 2011)
New Revision: 5966

Modified:
   pve-manager/pve2/www/new/Workspace.js
Log:
renew ticket every 15 minutes


Modified: pve-manager/pve2/www/new/Workspace.js
===================================================================
--- pve-manager/pve2/www/new/Workspace.js	2011-05-12 06:27:12 UTC (rev 5965)
+++ pve-manager/pve2/www/new/Workspace.js	2011-05-12 06:59:47 UTC (rev 5966)
@@ -2,7 +2,7 @@
  * Workspace base class
  *
  * popup login window when auth fails (call onLogin handler)
- * fixme: update (re-login) ticket at regular interval
+ * update (re-login) ticket every 15 minutes
  *
  */
 
@@ -20,6 +20,16 @@
 
     onLogin: function(loginData) {},
 
+    // private
+    updateLoginData: function(loginData) {
+	var me = this;
+	me.loginData = loginData;
+	PVE.CSRFPreventionToken = loginData.CSRFPreventionToken;
+	PVE.UserName = loginData.username;
+	me.onLogin(loginData);
+    },
+
+    // private
     showLogin: function() {
 	var me = this;
 
@@ -31,16 +41,13 @@
 	    me.login = Ext.create('PVE.window.LoginWindow', {
 		handler: function(data) {
 		    me.login = null;
-		    me.loginData = data;
-		    PVE.CSRFPreventionToken = data.CSRFPreventionToken;
-		    PVE.UserName = data.username;
-		    me.onLogin(me.loginData);
+		    me.updateLoginData(data);
 		}
 	    });
 	}
 	me.onLogin(null);
         me.login.show();
-   },
+    },
 
     initComponent : function() {
 	var me = this;
@@ -63,6 +70,30 @@
 	else 
 	    if (me.loginData)
 		me.onLogin(me.loginData);
+
+	Ext.TaskManager.start({
+	    run: function() {
+		var ticket = PVE.Utils.authOK();
+		if (!ticket || !PVE.UserName)
+		    return;
+
+		Ext.Ajax.request({
+		    params: { 
+			username: PVE.UserName,
+			password: ticket
+		    },
+		    url: '/api2/json/access/ticket',
+		    method: 'POST',
+		    success: function(response, opts) {
+			// cookie is automatically updated
+			var obj = Ext.decode(response.responseText);
+			me.updateLoginData(obj.data);
+		    }
+		});
+	    },
+	    interval: 15*1000
+	});
+
     }
 });
 




More information about the pve-devel mailing list