ui: tfa: mask panels for not currently used types

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-04-11 11:32:01 +02:00 committed by Thomas Lamprecht
parent da89881018
commit ac3daab801
2 changed files with 23 additions and 5 deletions

View File

@ -167,12 +167,13 @@ Ext.define('PVE.window.TFAEdit', {
}); });
me.down('#qrbox').getEl().appendChild(me.qrdiv); me.down('#qrbox').getEl().appendChild(me.qrdiv);
viewmodel.set('has_tfa', me.hasTFA); viewmodel.set('has_tfa', me.tfa_type !== undefined);
if (!me.hasTFA) { if (!me.tfa_type) {
this.randomizeSecret(); this.randomizeSecret();
} else { } else {
me.down('#qrbox').setVisible(false); me.down('#qrbox').setVisible(false);
me.lookup('challenge').setVisible(false); me.lookup('challenge').setVisible(false);
this.updatePanelMask(me.down('#totp-panel'));
} }
if (Proxmox.UserName === 'root@pam') { if (Proxmox.UserName === 'root@pam') {
@ -185,10 +186,23 @@ Ext.define('PVE.window.TFAEdit', {
tabchange: function(panel, newcard) { tabchange: function(panel, newcard) {
var viewmodel = this.getViewModel(); var viewmodel = this.getViewModel();
viewmodel.set('in_totp_tab', newcard.itemId === 'totp-panel'); 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() { applySettings: function() {
var me = this; var me = this;
var values = me.lookup('totp_form').getValues(); var values = me.lookup('totp_form').getValues();
@ -305,6 +319,7 @@ Ext.define('PVE.window.TFAEdit', {
xtype: 'panel', xtype: 'panel',
title: 'TOTP', title: 'TOTP',
itemId: 'totp-panel', itemId: 'totp-panel',
tfa_type: 'totp',
border: false, border: false,
layout: { layout: {
type: 'vbox', type: 'vbox',
@ -407,6 +422,7 @@ Ext.define('PVE.window.TFAEdit', {
title: 'U2F', title: 'U2F',
itemId: 'u2f-panel', itemId: 'u2f-panel',
reference: 'u2f_panel', reference: 'u2f_panel',
tfa_type: 'u2f',
border: false, border: false,
padding: '5 5', padding: '5 5',
layout: { layout: {
@ -457,7 +473,8 @@ Ext.define('PVE.window.TFAEdit', {
text: gettext('Register U2F Device'), text: gettext('Register U2F Device'),
handler: 'startU2FRegistration', handler: 'startU2FRegistration',
bind: { bind: {
hidden: '{in_totp_tab}' hidden: '{in_totp_tab}',
disabled: '{has_tfa}'
} }
}, },
{ {

View File

@ -85,9 +85,10 @@ Ext.define('PVE.dc.UserView', {
selModel: sm, selModel: sm,
handler: function(btn, event, rec) { handler: function(btn, event, rec) {
var d = rec.data; var d = rec.data;
var tfa_type = PVE.Parser.parseTfaType(d.keys);
var win = Ext.create('PVE.window.TFAEdit',{ var win = Ext.create('PVE.window.TFAEdit',{
hasTFA: d.keys != undefined && d.keys.length, tfa_type: tfa_type,
userid: d.userid userid: d.userid
}); });
win.on('destroy', reload); win.on('destroy', reload);
win.show(); win.show();