| 1588 | |
| 1589 | // ---------- SETUP MODE ---------- |
| 1590 | async function createUserSetup(username, password, isAdmin) { |
| 1591 | const csrf = window.csrfToken || localStorage.getItem('csrf') || ''; |
| 1592 | const headers = { 'Content-Type': 'application/json' }; |
| 1593 | if (csrf) headers['X-CSRF-Token'] = csrf; |
| 1594 | |
| 1595 | const res = await fetch('/api/admin/addUser.php?setup=1', { |
| 1596 | method: 'POST', |
| 1597 | credentials: 'include', |
| 1598 | headers, |
| 1599 | body: JSON.stringify({ username, password, isAdmin: true, admin: true, grant_admin: true }) |
| 1600 | }); |
| 1601 | |
| 1602 | let j = {}; |
| 1603 | try { j = await res.json(); } catch (e) { } |
| 1604 | if (!res.ok || j.error) throw new Error(j.error || `Add user failed (${res.status})`); |
| 1605 | return true; |
| 1606 | } |
| 1607 | function bindSetupAddUser() { |
| 1608 | const form = document.getElementById('addUserForm'); |
| 1609 | if (!form || form.__bound) return; |