mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-06-12 13:08:53 +00:00

store.findRecord returns the first match, and by default matches the beginning of the strings not the whole without this, with multple realms with the same name, but different tfa settings, the login window can show the tfa input box even when the selected realm has no tfa active Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
Ext.define('PVE.form.RealmComboBox', {
|
|
extend: 'Ext.form.field.ComboBox',
|
|
alias: ['widget.pveRealmComboBox'],
|
|
|
|
fieldLabel: gettext('Realm'),
|
|
name: 'realm',
|
|
queryMode: 'local',
|
|
allowBlank: false,
|
|
forceSelection: true,
|
|
autoSelect: false,
|
|
triggerAction: 'all',
|
|
valueField: 'realm',
|
|
displayField: 'descr',
|
|
getState: function() {
|
|
return { value: this.getValue() };
|
|
},
|
|
applyState : function(state) {
|
|
if (state && state.value) {
|
|
this.setValue(state.value);
|
|
}
|
|
},
|
|
stateEvents: [ 'select' ],
|
|
stateful: true, // last chosen auth realm is saved between page reloads
|
|
id: 'pveloginrealm', // We need stable ids when using stateful, not autogenerated
|
|
stateID: 'pveloginrealm',
|
|
|
|
needOTP: function(realm) {
|
|
var me = this;
|
|
// use exact match
|
|
var rec = me.store.findRecord('realm', realm, 0, false, false, true);
|
|
return rec && rec.data && rec.data.tfa ? rec.data.tfa : undefined;
|
|
},
|
|
|
|
initComponent: function() {
|
|
var me = this;
|
|
|
|
me.store = Ext.create('Ext.data.Store', {
|
|
model: 'pve-domains'
|
|
});
|
|
|
|
me.callParent();
|
|
|
|
me.store.load({
|
|
callback: function(r, o, success) {
|
|
if (success) {
|
|
var def = me.getValue();
|
|
if (!def || !me.store.findRecord('realm', def)) {
|
|
def = 'pam';
|
|
Ext.each(r, function(record) {
|
|
if (record.data && record.data["default"]) {
|
|
def = record.data.realm;
|
|
}
|
|
});
|
|
}
|
|
if (def) {
|
|
me.setValue(def);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|