change PVE.UserName/CSRFPreventionToken to Proxmox

this is now all in the widget-toolkit and needs to be
set/read to/from there, else we possibly get an inconsistent view on
those

this fixes as issue, where after login the ResourceStore would not update

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Tested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dominik Csapak 2018-01-25 14:36:51 +01:00
parent 2bb03197d3
commit 35a04562fd
6 changed files with 12 additions and 23 deletions

View File

@ -36,8 +36,6 @@
<script type="text/javascript">
if (typeof(PVE) === 'undefined') PVE = {};
PVE.UserName = '[% username %]'
PVE.CSRFPreventionToken = '[% token %]';
Ext.History.fieldid = 'x-history-field';
Ext.onReady(function() { Ext.create('PVE.StdWorkspace');});
</script>

View File

@ -20,15 +20,6 @@ Ext.Ajax.defaultHeaders = {
'Accept': 'application/json'
};
Ext.Ajax.on('beforerequest', function(conn, options) {
if (PVE.CSRFPreventionToken) {
if (!options.headers) {
options.headers = {};
}
options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
}
});
Ext.define('PVE.Utils', { utilities: {
// this singleton contains miscellaneous utilities

View File

@ -19,8 +19,8 @@ Ext.define('PVE.Workspace', {
updateLoginData: function(loginData) {
var me = this;
me.loginData = loginData;
PVE.CSRFPreventionToken = loginData.CSRFPreventionToken;
PVE.UserName = loginData.username;
Proxmox.CSRFPreventionToken = loginData.CSRFPreventionToken;
Proxmox.UserName = loginData.username;
if (loginData.cap) {
Ext.state.Manager.set('GuiCap', loginData.cap);
@ -37,7 +37,7 @@ Ext.define('PVE.Workspace', {
var me = this;
Proxmox.Utils.authClear();
PVE.UserName = null;
Proxmox.UserName = null;
me.loginData = null;
if (!me.login) {
@ -78,13 +78,13 @@ Ext.define('PVE.Workspace', {
Ext.TaskManager.start({
run: function() {
var ticket = Proxmox.Utils.authOK();
if (!ticket || !PVE.UserName) {
if (!ticket || !Proxmox.UserName) {
return;
}
Ext.Ajax.request({
params: {
username: PVE.UserName,
username: Proxmox.UserName,
password: ticket
},
url: '/api2/json/access/ticket',
@ -164,8 +164,8 @@ Ext.define('PVE.StdWorkspace', {
var ui = me.query('#userinfo')[0];
if (PVE.UserName) {
var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + PVE.UserName + "'");
if (Proxmox.UserName) {
var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + Proxmox.UserName + "'");
ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>');
} else {
ui.update('');

View File

@ -197,7 +197,7 @@ Ext.define('PVE.lxc.RessourceView', {
var isDisk = (rowdef.tdCls == 'pve-itype-icon-storage');
var noedit = rec.data['delete'] || !rowdef.editor;
if (!noedit && PVE.UserName !== 'root@pam' && key.match(/^mp\d+$/)) {
if (!noedit && Proxmox.UserName !== 'root@pam' && key.match(/^mp\d+$/)) {
var mp = PVE.Parser.parseLxcMountPoint(value);
if (mp.type !== 'volume') {
noedit = true;

View File

@ -217,7 +217,7 @@ Ext.define('PVE.node.Config', {
xtype: 'proxmoxNodeAPT',
upgradeBtn: {
xtype: 'pveConsoleButton',
disabled: PVE.UserName !== 'root@pam',
disabled: Proxmox.UserName !== 'root@pam',
text: gettext('Upgrade'),
consoleType: 'upgrade',
nodename: nodename

View File

@ -107,8 +107,8 @@ Ext.define('PVE.Workspace', { statics: {
updateLoginData: function(loginData) {
PVE.Workspace.loginData = loginData;
PVE.CSRFPreventionToken = loginData.CSRFPreventionToken;
PVE.UserName = loginData.username;
Proxmox.CSRFPreventionToken = loginData.CSRFPreventionToken;
Proxmox.UserName = loginData.username;
// creates a session cookie (expire = null)
// that way the cookie gets deleted after browser window close
@ -119,7 +119,7 @@ Ext.define('PVE.Workspace', { statics: {
showLogin: function() {
Proxmox.Utils.authClear();
PVE.UserName = null;
Proxmox.UserName = null;
PVE.Workspace.loginData = null;
PVE.Workspace.gotoPage('');