From 75b169e11ddbf936d5cf3543ffc876e302bbf2a0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 5 Nov 2024 20:32:09 -0800 Subject: [PATCH] refac: ldap auth page --- backend/open_webui/main.py | 2 +- src/routes/auth/+page.svelte | 189 ++++++++++++----------------------- 2 files changed, 67 insertions(+), 124 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index a252dc10b..c0650e444 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2235,9 +2235,9 @@ async def get_app_config(request: Request): "features": { "auth": WEBUI_AUTH, "auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER), + "enable_ldap": webui_app.state.config.ENABLE_LDAP, "enable_signup": webui_app.state.config.ENABLE_SIGNUP, "enable_login_form": webui_app.state.config.ENABLE_LOGIN_FORM, - "enable_ldap_form": webui_app.state.config.ENABLE_LDAP, **( { "enable_web_search": retrieval_app.state.config.ENABLE_RAG_WEB_SEARCH, diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index 0c9156e7e..96a6cd1ee 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -20,12 +20,7 @@ let loaded = false; - let mode = - !$config?.features.enable_login_form && - Object.keys($config?.oauth?.providers ?? {}).length == 0 && - $config?.features.enable_ldap_form - ? 'ldap' - : 'signin'; + let mode = $config?.features.enable_ldap ? 'ldap' : 'signin'; let name = ''; let email = ''; @@ -34,13 +29,6 @@ let ldapUsername = ''; let ldapPassword = ''; - $: showSwitchButtonForSignInForm = - ($config?.features.enable_ldap_form && mode !== 'ldap') || - ($config?.features.enable_login_form && mode === 'ldap'); - - $: showOtherSignInMethods = - Object.keys($config?.oauth?.providers ?? {}).length > 0 || showSwitchButtonForSignInForm; - const setSessionUser = async (sessionUser) => { if (sessionUser) { console.log(sessionUser); @@ -144,12 +132,7 @@ bind:show={onboarding} getStartedHandler={() => { onboarding = false; - mode = - !$config?.features.enable_login_form && - Object.keys($config?.oauth?.providers ?? {}).length == 0 && - $config?.features.enable_ldap_form - ? 'ldap' - : 'signup'; + mode = $config?.features.enable_ldap ? 'ldap' : 'signup'; }} /> @@ -209,7 +192,7 @@ {/if} - {#if (mode === 'signup' || mode === 'ldap') && ($config?.onboarding ?? false)} + {#if $config?.onboarding ?? false}
ⓘ {$WEBUI_NAME} {$i18n.t( @@ -219,7 +202,7 @@ {/if}
- {#if $config?.features.enable_login_form || $config?.features.enable_ldap_form} + {#if $config?.features.enable_login_form}
{#if mode === 'signup'}
@@ -275,57 +258,56 @@
{/if} - - {#if $config?.features.enable_ldap_form && mode === 'ldap'} -
- -
- {:else if $config?.features.enable_login_form && mode !== 'ldap'} -
- - - {#if $config?.features.enable_signup && !($config?.onboarding ?? false)} -
+
+ {#if $config?.features.enable_login_form} + {#if mode === 'ldap'} + + {:else} + - -
+ {#if $config?.features.enable_signup && !($config?.onboarding ?? false)} +
+ {mode === 'signin' + ? $i18n.t("Don't have an account?") + : $i18n.t('Already have an account?')} + + +
+ {/if} {/if} -
- {/if} + {/if} +
- {#if showOtherSignInMethods} + {#if Object.keys($config?.oauth?.providers ?? {}).length > 0}

{#if $config?.features.enable_login_form} @@ -417,64 +399,25 @@ > {/if} +
+ {/if} - {#if showSwitchButtonForSignInForm} - - {/if} + {/if}