feat: added setup panel for admin user

pull/243/head
Josh Moore 1 year ago
parent 346aa9b97d
commit e515849580

@ -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);

@ -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

Loading…
Cancel
Save