[pve-devel] r5770 - in pve-manager/pve2/www/new: . window

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 30 07:14:58 CEST 2011


Author: dietmar
Date: 2011-03-30 07:14:58 +0200 (Wed, 30 Mar 2011)
New Revision: 5770

Modified:
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/Workspace.js
   pve-manager/pve2/www/new/index.pl
   pve-manager/pve2/www/new/window/LoginWindow.js
Log:
display user name


Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-03-30 05:10:16 UTC (rev 5769)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-03-30 05:14:58 UTC (rev 5770)
@@ -11,10 +11,10 @@
 };
 
 Ext.Ajax.on('beforerequest', function(conn, options) {
-    if (PVECSRFPreventionToken) {
+    if (PVE.CSRFPreventionToken) {
 	if (!options.headers) 
 	    options.headers = {};
-	options.headers['CSRFPreventionToken'] = PVECSRFPreventionToken;
+	options.headers['CSRFPreventionToken'] = PVE.CSRFPreventionToken;
     }
 });
 

Modified: pve-manager/pve2/www/new/Workspace.js
===================================================================
--- pve-manager/pve2/www/new/Workspace.js	2011-03-30 05:10:16 UTC (rev 5769)
+++ pve-manager/pve2/www/new/Workspace.js	2011-03-30 05:14:58 UTC (rev 5770)
@@ -29,17 +29,37 @@
 	var self = this;
 
 	PVE.Utils.authClear();
+	PVE.UserName = null;
 
 	if (!self.login) {
 	    self.login = Ext.create('PVE.window.LoginWindow', {
-		handler: function() {
+		handler: function(data) {
 		    self.login = null;
+
+		    PVE.CSRFPreventionToken = data.CSRFPreventionToken;
+		    PVE.UserName = data.username;
+
+		    self.updateUserInfo();
 		}
 	    });
 	}
         self.login.show();
+	self.updateUserInfo();
     },
 
+    updateUserInfo: function() {
+	var self = this;
+
+	var ui = self.query('#userinfo')[0];
+
+	if (PVE.UserName) {
+	    ui.update("You are logged in as '" + PVE.UserName + "'");
+	} else {
+	    ui.update('');
+	}
+	ui.doLayout();
+    },
+
     initComponent : function() {
 	var self = this;
 
@@ -74,16 +94,22 @@
 		    border: false,
 		    items: [
 			{
-			    margins: '0 0 0 2',
+			    margins: '0 0 0 4',
 			    html: '<a target=_blank href="http://www.proxmox.com">' +
 				'<img height=30 width=209 src="/images/proxmox_logo.png"/></a>'
 			},
 			{
+			    minWidth: 200,
 			    flex: 1,
-			    html: '<span class="x-panel-header-text">Proxmox Virtual Environment</span><br>Version 2.0',
+			    html: '<span class="x-panel-header-text">Proxmox Virtual Environment</span><br>Version ' + PVE.GUIVersion,
 			},
 			{
 			    pack: 'end',
+			    margins: '8 10 0 10',
+			    id: 'userinfo',
+			},
+			{
+			    pack: 'end',
 			    width: 80,
 			    margins: '3 5 0 0',
 			    xtype: 'button',
@@ -135,7 +161,9 @@
 
         if (!PVE.Utils.authOK())
 	    self.showLogin();
- 
+	else 
+	    self.updateUserInfo();
+
     }
 });
 

Modified: pve-manager/pve2/www/new/index.pl
===================================================================
--- pve-manager/pve2/www/new/index.pl	2011-03-30 05:10:16 UTC (rev 5769)
+++ pve-manager/pve2/www/new/index.pl	2011-03-30 05:14:58 UTC (rev 5770)
@@ -4,6 +4,7 @@
 use mod_perl2 '1.9922';
 use Encode;
 use CGI;
+use PVE::pvecfg;
 use PVE::AccessControl;
 use PVE::REST;
 
@@ -24,14 +25,16 @@
 # so we must be very careful here 
 
 my $r = Apache2::RequestUtil->request();
-
+my $username;
 my $token = 'null';
 if (my $cookie = $r->headers_in->{Cookie}) {
     my $ticket = PVE::REST::extract_auth_cookie($cookie);
-    if (PVE::AccessControl::verify_ticket($ticket, 1)) {
+    if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) {
 	$token = PVE::AccessControl::assemble_csrf_prevention_token($ticket);
     }
 }
+my $version = PVE::pvecfg::version() . "/" . PVE::pvecfg::repoid();
+$username = '' if !$username;
 
 my $cgi = CGI->new($r);
 my %args =  $cgi->Vars();
@@ -49,7 +52,10 @@
 }
 
 my $jssrc = <<_EOJS;
-PVECSRFPreventionToken = '$token';
+PVE.GUIVersion = '$version';
+PVE.UserName = '$username';
+PVE.CSRFPreventionToken = '$token';
+
 Ext.require(['*']);
 Ext.onReady(function() {
     Ext.create('PVE.Workspace');

Modified: pve-manager/pve2/www/new/window/LoginWindow.js
===================================================================
--- pve-manager/pve2/www/new/window/LoginWindow.js	2011-03-30 05:10:16 UTC (rev 5769)
+++ pve-manager/pve2/www/new/window/LoginWindow.js	2011-03-30 05:14:58 UTC (rev 5770)
@@ -18,11 +18,8 @@
 		success: function(f, resp){
 		    self.el.unmask();
 		    
-		    if (resp.result && resp.result.data)
-			PVECSRFPreventionToken = resp.result.data.CSRFPreventionToken;
-
 		    var handler = self.handler || Ext.emptyFn;
-		    handler.call(self);
+		    handler.call(self, resp.result.data);
 		    self.close();
 		}
 	    });



More information about the pve-devel mailing list