ui: tfa: save last used TFA method and prefer it next time
simple heuristic for those people who always prefer a specific TFA method and have the others only as backup. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
b2fc6f9228
commit
6ee85d57be
@ -280,17 +280,22 @@ Ext.define('PBS.login.TfaWindow', {
|
|||||||
throw "no challenge given";
|
throw "no challenge given";
|
||||||
}
|
}
|
||||||
|
|
||||||
let firstAvailableTab = -1, i = 0;
|
let lastTabId = me.getLastTabUsed();
|
||||||
|
let initialTab = -1, i = 0;
|
||||||
for (const k of ['webauthn', 'totp', 'recovery']) {
|
for (const k of ['webauthn', 'totp', 'recovery']) {
|
||||||
const available = !!challenge[k];
|
const available = !!challenge[k];
|
||||||
vm.set(`availabelChallenge.${k}`, available);
|
vm.set(`availabelChallenge.${k}`, available);
|
||||||
|
|
||||||
if (firstAvailableTab < 0 && available) {
|
if (available) {
|
||||||
firstAvailableTab = i;
|
if (i === lastTabId) {
|
||||||
|
initialTab = i;
|
||||||
|
} else if (initialTab < 0) {
|
||||||
|
initialTab = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
view.down('tabpanel').setActiveTab(firstAvailableTab);
|
view.down('tabpanel').setActiveTab(initialTab);
|
||||||
|
|
||||||
if (challenge.recovery) {
|
if (challenge.recovery) {
|
||||||
me.lookup('availableRecovery').update(Ext.String.htmlEncode(
|
me.lookup('availableRecovery').update(Ext.String.htmlEncode(
|
||||||
@ -320,6 +325,7 @@ Ext.define('PBS.login.TfaWindow', {
|
|||||||
newField.focus();
|
newField.focus();
|
||||||
newField.validate();
|
newField.validate();
|
||||||
}
|
}
|
||||||
|
this.saveLastTabUsed(tabPanel, newCard);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'field': {
|
'field': {
|
||||||
@ -331,6 +337,20 @@ Ext.define('PBS.login.TfaWindow', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
saveLastTabUsed: function(tabPanel, card) {
|
||||||
|
let id = tabPanel.items.indexOf(card);
|
||||||
|
window.localStorage.setItem('PBS.TFALogin.lastTab', JSON.stringify({ id }));
|
||||||
|
},
|
||||||
|
|
||||||
|
getLastTabUsed: function() {
|
||||||
|
let data = window.localStorage.getItem('PBS.TFALogin.lastTab');
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
let last = JSON.parse(data);
|
||||||
|
return last.id;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
let me = this;
|
let me = this;
|
||||||
let view = me.getView();
|
let view = me.getView();
|
||||||
|
Loading…
Reference in New Issue
Block a user