pve-manager/www/manager6/form/RealmComboBox.js
Dominik Csapak 54b590f0c5 only use exact match in pveRealmSelector
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>
2016-08-17 12:35:00 +02:00

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);
}
}
}
});
}
});