diff --git a/frontend/setup.mts b/frontend/setup.mts index 570e284..fcac8ba 100644 --- a/frontend/setup.mts +++ b/frontend/setup.mts @@ -25,6 +25,9 @@ document.addEventListener('DOMContentLoaded', () => { mySqlPassword: document.querySelector('#mysql-password') as SlInput, mySqlDatabase: document.querySelector('#mysql-database') as SlInput, + userUsername: document.querySelector('#user-username') as SlInput, + userPassword: document.querySelector('#user-password') as SlInput, + submitButton: document.querySelector('#submit') as SlButton, }; @@ -68,6 +71,13 @@ document.addEventListener('DOMContentLoaded', () => { }; } + // ! Make sure the admin user fields are set + const adminErrReset = (message: string) => (Elements.submitButton.disabled = false, alert(message)); + if (Elements.userUsername.value == null || Elements.userUsername.value === '') + return adminErrReset('Admin username is required!'); + if (Elements.userPassword.value == null || Elements.userPassword.value === '') + return adminErrReset('Admin password is required!'); + // Do setup fetch('/setup', { method: 'POST', @@ -80,7 +90,24 @@ document.addEventListener('DOMContentLoaded', () => { message: string }) => { if (!data.success) alert(data.message); - else window.location.href = '/'; + + // Create first user (YES I KNOW THIS NESTING IS GROSS) + else return fetch('/api/user', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + username: Elements.userUsername.value, + password: Elements.userPassword.value, + admin: true + }) + }).then((res) => res.json()) + .then((data: { + success: boolean, + message: string + }) => { + alert(data.message); + if (data.success) window.location.href = '/dashboard'; + }); }) .catch((err) => errAlert('POST to /setup failed!', err)) .finally(() => Elements.submitButton.disabled = false); diff --git a/views2/setup.pug b/views2/setup.pug index 5076167..d69bcb5 100644 --- a/views2/setup.pug +++ b/views2/setup.pug @@ -39,6 +39,14 @@ html.dark.sl-theme-dark(lang='en') h3.setup-text-item-title Maximum file size (MB) sl-input#uploads-filesize(type='number' placeholder='50'): sl-icon(slot='prefix' name='fas-file' library='fa') + //- * Admin User + h2.setup-text-section-header.mt-4 Admin User + .setup-panel + h3.setup-text-item-title Username + sl-input#user-username(type='text' placeholder='admin' clearable): sl-icon(slot='prefix' name='fas-user' library='fa') + h3.setup-text-item-title Password + sl-input#user-password(type='password' placeholder='the-most-secure' clearable): sl-icon(slot='prefix' name='fas-lock' library='fa') + //- * S3 h2.setup-text-section-header.mt-4 S3 #[span.setup-text-optional optional] .setup-panel