This commit is contained in:
Timothy J. Baek 2024-11-05 20:47:23 -08:00
parent 75b169e11d
commit 547682c674
2 changed files with 16 additions and 15 deletions

View File

@ -2216,16 +2216,17 @@ async def get_app_config(request: Request):
if data is not None and "id" in data: if data is not None and "id" in data:
user = Users.get_user_by_id(data["id"]) user = Users.get_user_by_id(data["id"])
user_count = 0 onboarding = False
if user is None: if user is None:
user_count = Users.get_num_users() user_count = Users.get_num_users()
onboarding = user_count == 0
return { return {
**({"onboarding": True} if onboarding else {}),
"status": True, "status": True,
"name": WEBUI_NAME, "name": WEBUI_NAME,
"version": VERSION, "version": VERSION,
"default_locale": str(DEFAULT_LOCALE), "default_locale": str(DEFAULT_LOCALE),
**({"onboarding": True} if user_count is 0 else {}),
"oauth": { "oauth": {
"providers": { "providers": {
name: config.get("name", name) name: config.get("name", name)

View File

@ -27,7 +27,6 @@
let password = ''; let password = '';
let ldapUsername = ''; let ldapUsername = '';
let ldapPassword = '';
const setSessionUser = async (sessionUser) => { const setSessionUser = async (sessionUser) => {
if (sessionUser) { if (sessionUser) {
@ -64,6 +63,14 @@
await setSessionUser(sessionUser); await setSessionUser(sessionUser);
}; };
const ldapSignInHandler = async () => {
const sessionUser = await ldapUserSignIn(ldapUsername, password).catch((error) => {
toast.error(error);
return null;
});
await setSessionUser(sessionUser);
};
const submitHandler = async () => { const submitHandler = async () => {
if (mode === 'ldap') { if (mode === 'ldap') {
await ldapSignInHandler(); await ldapSignInHandler();
@ -74,14 +81,6 @@
} }
}; };
const ldapSignInHandler = async () => {
const sessionUser = await ldapUserSignIn(ldapUsername, ldapPassword).catch((error) => {
toast.error(error);
return null;
});
await setSessionUser(sessionUser);
};
const checkOauthCallback = async () => { const checkOauthCallback = async () => {
if (!$page.url.hash) { if (!$page.url.hash) {
return; return;
@ -113,6 +112,7 @@
await goto('/'); await goto('/');
} }
await checkOauthCallback(); await checkOauthCallback();
loaded = true; loaded = true;
if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) { if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) {
await signInHandler(); await signInHandler();
@ -175,7 +175,8 @@
<div class=" my-auto pb-10 w-full dark:text-gray-100"> <div class=" my-auto pb-10 w-full dark:text-gray-100">
<form <form
class=" flex flex-col justify-center" class=" flex flex-col justify-center"
on:submit|preventDefault={() => { on:submit={(e) => {
e.preventDefault();
submitHandler(); submitHandler();
}} }}
> >
@ -265,9 +266,7 @@
class="bg-gray-700/5 hover:bg-gray-700/10 dark:bg-gray-100/5 dark:hover:bg-gray-100/10 dark:text-gray-300 dark:hover:text-white transition w-full rounded-full font-medium text-sm py-2.5" class="bg-gray-700/5 hover:bg-gray-700/10 dark:bg-gray-100/5 dark:hover:bg-gray-100/10 dark:text-gray-300 dark:hover:text-white transition w-full rounded-full font-medium text-sm py-2.5"
type="submit" type="submit"
> >
{($config?.onboarding ?? false) {$i18n.t('Authenticate')}
? $i18n.t('Authenticate as Admin')
: $i18n.t('Authenticate')}
</button> </button>
{:else} {:else}
<button <button
@ -406,6 +405,7 @@
<div class="mt-2"> <div class="mt-2">
<button <button
class="flex justify-center items-center text-xs w-full text-center underline" class="flex justify-center items-center text-xs w-full text-center underline"
type="button"
on:click={() => { on:click={() => {
if (mode === 'ldap') if (mode === 'ldap')
mode = ($config?.onboarding ?? false) ? 'signup' : 'signin'; mode = ($config?.onboarding ?? false) ? 'signup' : 'signin';