mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: handle user_verify keyDown (#752)
This commit is contained in:
1 parent
3794bef262
commit
c57816d8ee
1 file changed
+12
-3
@@ -45,15 +45,15 @@ async function chooseAction(authn?: boolean) {
|
|||||||
<h3>${i18n('Two Factor Authentication')}</h3>
|
<h3>${i18n('Two Factor Authentication')}</h3>
|
||||||
<p>${i18n('Your account has two factor authentication enabled. Please choose an authenticator to verify.')}</p>
|
<p>${i18n('Your account has two factor authentication enabled. Please choose an authenticator to verify.')}</p>
|
||||||
<div style="${authn ? '' : 'display:none;'}">
|
<div style="${authn ? '' : 'display:none;'}">
|
||||||
<input value="${i18n('Use Authenticator')}" class="expanded rounded primary button" data-action="webauthn" autofocus>
|
<button class="expanded rounded primary button" data-action="webauthn">${i18n('Use Authenticator')}</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>${i18n('6-Digit Code')}
|
<label>${i18n('6-Digit Code')}
|
||||||
<div class="textbox-container">
|
<div class="textbox-container">
|
||||||
<input class="textbox" type="number" name="tfa_code" autocomplete="off" autofocus>
|
<input class="textbox" type="number" name="tfa_code" autocomplete="off" data-autofocus>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
<input value="${i18n('Use TFA Code')}" class="expanded rounded primary button" data-action="tfa">
|
<button class="expanded rounded primary button" data-action="tfa">${i18n('Use TFA Code')}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
@@ -88,8 +88,17 @@ export default new AutoloadPage('user_verify', () => {
|
|||||||
}
|
}
|
||||||
const { authn, tfa } = info.uname || info.mail;
|
const { authn, tfa } = info.uname || info.mail;
|
||||||
if (authn || tfa) {
|
if (authn || tfa) {
|
||||||
|
const handleKeyDown = (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
const code = $('[name="tfa_code"]').val() as string;
|
||||||
|
if (code) $('[data-action="tfa"]').trigger('click');
|
||||||
|
else $('[data-action]').trigger('click');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$(document).on('keydown', handleKeyDown);
|
||||||
let action = (authn && tfa) ? await chooseAction(true) : '';
|
let action = (authn && tfa) ? await chooseAction(true) : '';
|
||||||
action ||= tfa ? await chooseAction(false) : 'webauthn';
|
action ||= tfa ? await chooseAction(false) : 'webauthn';
|
||||||
|
$(document).off('keydown', handleKeyDown);
|
||||||
if (action === 'webauthn') {
|
if (action === 'webauthn') {
|
||||||
const challenge = await verifywebauthn(form);
|
const challenge = await verifywebauthn(form);
|
||||||
if (challenge) form['authnChallenge'].value = challenge;
|
if (challenge) form['authnChallenge'].value = challenge;
|
||||||
|
|||||||
Reference in new issue
Block a user