[pve-devel] [PATCH manager 3/4] ui: tfa: mask panels for not currently used types

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Apr 11 11:32:01 CEST 2019


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 www/manager6/dc/TFAEdit.js  | 23 ++++++++++++++++++++---
 www/manager6/dc/UserView.js |  5 +++--
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/www/manager6/dc/TFAEdit.js b/www/manager6/dc/TFAEdit.js
index f0f4e5f4..49c39b4e 100644
--- a/www/manager6/dc/TFAEdit.js
+++ b/www/manager6/dc/TFAEdit.js
@@ -167,12 +167,13 @@ Ext.define('PVE.window.TFAEdit', {
 		    });
 		    me.down('#qrbox').getEl().appendChild(me.qrdiv);
 
-		    viewmodel.set('has_tfa', me.hasTFA);
-		    if (!me.hasTFA) {
+		    viewmodel.set('has_tfa', me.tfa_type !== undefined);
+		    if (!me.tfa_type) {
 			this.randomizeSecret();
 		    } else {
 			me.down('#qrbox').setVisible(false);
 			me.lookup('challenge').setVisible(false);
+			this.updatePanelMask(me.down('#totp-panel'));
 		    }
 
 		    if (Proxmox.UserName === 'root at pam') {
@@ -185,10 +186,23 @@ Ext.define('PVE.window.TFAEdit', {
 		tabchange: function(panel, newcard) {
 		    var viewmodel = this.getViewModel();
 		    viewmodel.set('in_totp_tab', newcard.itemId === 'totp-panel');
+		    this.updatePanelMask(newcard);
 		}
 	    }
 	},
 
+	updatePanelMask: function(card) {
+	    var view = this.getView();
+	    var my_tfa_type = card.tfa_type;
+	    if (view.tfa_type && view.tfa_type.length && view.tfa_type !== my_tfa_type) {
+		card.mask(
+		    gettext('Another 2nd factor is currently configured.'),
+		    ['pve-static-mask']);
+	    } else {
+		card.unmask()
+	    }
+	},
+
 	applySettings: function() {
 	    var me = this;
 	    var values = me.lookup('totp_form').getValues();
@@ -305,6 +319,7 @@ Ext.define('PVE.window.TFAEdit', {
 		    xtype: 'panel',
 		    title: 'TOTP',
 		    itemId: 'totp-panel',
+		    tfa_type: 'totp',
 		    border: false,
 		    layout: {
 			type: 'vbox',
@@ -407,6 +422,7 @@ Ext.define('PVE.window.TFAEdit', {
 		    title: 'U2F',
 		    itemId: 'u2f-panel',
 		    reference: 'u2f_panel',
+		    tfa_type: 'u2f',
 		    border: false,
 		    padding: '5 5',
 		    layout: {
@@ -457,7 +473,8 @@ Ext.define('PVE.window.TFAEdit', {
 	    text: gettext('Register U2F Device'),
 	    handler: 'startU2FRegistration',
 	    bind: {
-		hidden: '{in_totp_tab}'
+		hidden: '{in_totp_tab}',
+		disabled: '{has_tfa}'
 	    }
 	},
 	{
diff --git a/www/manager6/dc/UserView.js b/www/manager6/dc/UserView.js
index e91486ab..8918fb2b 100644
--- a/www/manager6/dc/UserView.js
+++ b/www/manager6/dc/UserView.js
@@ -85,9 +85,10 @@ Ext.define('PVE.dc.UserView', {
 	    selModel: sm,
 	    handler: function(btn, event, rec) {
 		var d = rec.data;
+		var tfa_type = PVE.Parser.parseTfaType(d.keys);
 		var win = Ext.create('PVE.window.TFAEdit',{
-                    hasTFA: d.keys != undefined && d.keys.length,
-                    userid: d.userid
+		    tfa_type: tfa_type,
+		    userid: d.userid
 		});
 		win.on('destroy', reload);
 		win.show();
-- 
2.11.0





More information about the pve-devel mailing list