()
| 1605 | return true; |
| 1606 | } |
| 1607 | function bindSetupAddUser() { |
| 1608 | const form = document.getElementById('addUserForm'); |
| 1609 | if (!form || form.__bound) return; |
| 1610 | form.__bound = true; |
| 1611 | |
| 1612 | form.addEventListener('submit', async (ev) => { |
| 1613 | ev.preventDefault(); |
| 1614 | |
| 1615 | const usernameEl = document.getElementById('newUsername'); |
| 1616 | const passwordEl = document.getElementById('addUserPassword'); |
| 1617 | const isAdminEl = document.getElementById('isAdmin'); |
| 1618 | |
| 1619 | const username = (usernameEl?.value || '').trim(); |
| 1620 | const password = (passwordEl?.value || ''); |
| 1621 | const isAdmin = isAdminEl ? !!isAdminEl.checked : true; |
| 1622 | |
| 1623 | if (!username || !password) { |
| 1624 | alert(t('setup_enter_username_password')); |
| 1625 | (username ? passwordEl : usernameEl)?.focus(); |
| 1626 | return; |
| 1627 | } |
| 1628 | |
| 1629 | try { |
| 1630 | await primeCsrf(); |
| 1631 | await createUserSetup(username, password, isAdmin); |
| 1632 | const addModal = document.getElementById('addUserModal'); if (addModal) addModal.style.display = 'none'; |
| 1633 | window.setupMode = false; |
| 1634 | window.location.reload(); |
| 1635 | } catch (e) { |
| 1636 | alert(e.message || t('setup_create_user_failed')); |
| 1637 | if (!username) usernameEl?.focus(); |
| 1638 | else if (!password) passwordEl?.focus(); |
| 1639 | } |
| 1640 | }, true); |
| 1641 | } |
| 1642 | |
| 1643 | // ---------- pre-auth login ---------- |
| 1644 | function forceLoginVisible() { |
no test coverage detected