Skip to content

Commit ac3fa4b

Browse files
committed
Move 2FA setup into a modal popup instead of inline in card
1 parent 252a267 commit ac3fa4b

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

public/js/app.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,7 +3703,6 @@ function renderTotpDisabled(section) {
37033703
<i data-lucide="shield-plus" style="width:16px;height:16px"></i>
37043704
Enable Two-Factor Authentication
37053705
</button>
3706-
<div id="totp-setup-area"></div>
37073706
`;
37083707
$('#enable-totp-btn').addEventListener('click', handleTotpSetup);
37093708
initIcons();
@@ -3748,53 +3747,54 @@ async function renderTotpEnabled(section) {
37483747

37493748
async function handleTotpSetup() {
37503749
const btn = $('#enable-totp-btn');
3751-
const area = $('#totp-setup-area');
3752-
if (!btn || !area) return;
3750+
if (!btn) return;
37533751
btn.disabled = true;
37543752
btn.innerHTML = '<span class="spinner"></span>';
37553753

37563754
try {
37573755
const data = await api('/auth/totp/setup', { method: 'POST' });
3758-
area.innerHTML = html`
3759-
<div style="margin-top:20px;padding-top:20px;border-top:1px solid var(--border)">
3760-
<p style="font-size:0.85rem;color:var(--text-secondary);margin-bottom:16px;line-height:1.5">
3761-
Scan this QR code with your authenticator app (e.g. Google Authenticator, Authy, 2FAS).
3762-
</p>
3763-
<div style="text-align:center;margin-bottom:16px">
3764-
<img src="${data.qrCode}" alt="TOTP QR Code" style="width:180px;height:180px;border-radius:var(--radius-sm);background:#fff;padding:8px" />
3756+
3757+
const overlay = $('#modal-overlay');
3758+
const content = $('#modal-content');
3759+
content.innerHTML = html`
3760+
<div class="modal-title">
3761+
<i data-lucide="shield-plus" style="width:22px;height:22px;color:var(--accent-1);vertical-align:middle;margin-right:6px"></i>
3762+
Enable Two-Factor Authentication
3763+
</div>
3764+
<p style="font-size:0.85rem;color:var(--text-secondary);margin-bottom:16px;line-height:1.5">
3765+
Scan this QR code with your authenticator app (e.g. Google Authenticator, Authy, 2FAS).
3766+
</p>
3767+
<div style="text-align:center;margin-bottom:16px">
3768+
<img src="${data.qrCode}" alt="TOTP QR Code" style="width:180px;height:180px;border-radius:var(--radius-sm);background:#fff;padding:8px" />
3769+
</div>
3770+
<p style="font-size:0.78rem;color:var(--text-muted);text-align:center;margin-bottom:16px">
3771+
Or manually enter this key: <code style="background:var(--bg-secondary);padding:4px 8px;border-radius:4px;font-size:0.82rem;user-select:all">${data.secret}</code>
3772+
</p>
3773+
<form id="totp-enable-form">
3774+
<div class="form-group">
3775+
<label for="totp-verify-code">Enter the 6-digit code from your app</label>
3776+
<input type="text" id="totp-verify-code" placeholder="000000" required inputmode="numeric" maxlength="6" />
37653777
</div>
3766-
<p style="font-size:0.78rem;color:var(--text-muted);text-align:center;margin-bottom:16px">
3767-
Or manually enter this key: <code style="background:var(--bg-secondary);padding:4px 8px;border-radius:4px;font-size:0.82rem;user-select:all">${data.secret}</code>
3768-
</p>
3769-
<form id="totp-enable-form">
3770-
<div class="form-group">
3771-
<label for="totp-verify-code">Enter the 6-digit code from your app</label>
3772-
<input type="text" id="totp-verify-code" placeholder="000000" required inputmode="numeric" maxlength="6" />
3773-
</div>
3778+
<div id="totp-enable-status" style="font-size:0.82rem;color:var(--text-muted);margin-bottom:8px"></div>
3779+
<div class="modal-actions">
3780+
<button type="button" class="btn btn-ghost btn-full modal-cancel-btn">Cancel</button>
37743781
<button type="submit" class="btn btn-primary btn-full" id="totp-enable-btn">
37753782
Verify and Enable
37763783
</button>
3777-
<button type="button" class="btn btn-ghost btn-full" id="totp-setup-cancel-btn" style="margin-top:8px">
3778-
Cancel
3779-
</button>
3780-
</form>
3781-
<div id="totp-enable-status" style="margin-top:8px;font-size:0.82rem;color:var(--text-muted)"></div>
3782-
</div>
3784+
</div>
3785+
</form>
37833786
`;
3784-
btn.style.display = 'none';
3785-
$('#totp-enable-form').addEventListener('submit', handleTotpEnable);
3786-
$('#totp-setup-cancel-btn').addEventListener('click', () => {
3787-
area.innerHTML = '';
3788-
btn.disabled = false;
3789-
btn.innerHTML = '<i data-lucide="shield-plus" style="width:16px;height:16px"></i> Enable Two-Factor Authentication';
3790-
btn.style.display = '';
3791-
initIcons();
3792-
});
3787+
overlay.classList.add('open');
3788+
3789+
btn.disabled = false;
3790+
btn.innerHTML = '<i data-lucide="shield-plus" style="width:16px;height:16px"></i> Enable Two-Factor Authentication';
37933791
initIcons();
3792+
3793+
$('#totp-enable-form').addEventListener('submit', handleTotpEnable);
37943794
} catch (err) {
37953795
btn.disabled = false;
37963796
btn.innerHTML = '<i data-lucide="shield-plus" style="width:16px;height:16px"></i> Enable Two-Factor Authentication';
3797-
area.innerHTML = `<p style="color:var(--accent-red);font-size:0.82rem;margin-top:8px">${escapeHtml(err.message)}</p>`;
3797+
showToast(err.message, 'error');
37983798
}
37993799
}
38003800

0 commit comments

Comments
 (0)