From 12bd04d24d295b80a64130ab197a9694b31f780a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 28 Aug 2025 03:24:26 +0400 Subject: [PATCH] refac/enh --- backend/open_webui/env.py | 4 ++++ backend/open_webui/routers/auths.py | 8 +++++--- src/routes/auth/+page.svelte | 12 ++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 4762a66633..f0b26ae25c 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -404,6 +404,10 @@ except ValueError: #################################### WEBUI_AUTH = os.environ.get("WEBUI_AUTH", "True").lower() == "true" + +ENABLE_INITIAL_ADMIN_SIGNUP = ( + os.environ.get("ENABLE_INITIAL_ADMIN_SIGNUP", "False").lower() == "true" +) ENABLE_SIGNUP_PASSWORD_CONFIRMATION = ( os.environ.get("ENABLE_SIGNUP_PASSWORD_CONFIRMATION", "False").lower() == "true" ) diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 11254ec78c..b8670edeaa 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -29,6 +29,7 @@ from open_webui.env import ( WEBUI_AUTH_COOKIE_SAME_SITE, WEBUI_AUTH_COOKIE_SECURE, WEBUI_AUTH_SIGNOUT_REDIRECT_URL, + ENABLE_INITIAL_ADMIN_SIGNUP, SRC_LOG_LEVELS, ) from fastapi import APIRouter, Depends, HTTPException, Request, status @@ -569,9 +570,10 @@ async def signup(request: Request, response: Response, form_data: SignupForm): not request.app.state.config.ENABLE_SIGNUP or not request.app.state.config.ENABLE_LOGIN_FORM ): - raise HTTPException( - status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED - ) + if has_users or not ENABLE_INITIAL_ADMIN_SIGNUP: + raise HTTPException( + status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED + ) else: if has_users: raise HTTPException( diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index d4ce838251..8073f08a72 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -26,6 +26,8 @@ let mode = $config?.features.enable_ldap ? 'ldap' : 'signin'; + let form = null; + let name = ''; let email = ''; let password = ''; @@ -147,11 +149,13 @@ onMount(async () => { if ($user !== undefined) { - const redirectPath = querystringValue('redirect') || '/'; + const redirectPath = $page.url.searchParams.get('redirect') || '/'; goto(redirectPath); } await checkOauthCallback(); + form = $page.url.searchParams.get('form'); + loaded = true; setLogoImage(); @@ -246,7 +250,7 @@ {/if} - {#if $config?.features.enable_login_form || $config?.features.enable_ldap} + {#if $config?.features.enable_login_form || $config?.features.enable_ldap || form}
{#if mode === 'signup'}
@@ -337,7 +341,7 @@
{/if}
- {#if $config?.features.enable_login_form || $config?.features.enable_ldap} + {#if $config?.features.enable_login_form || $config?.features.enable_ldap || form} {#if mode === 'ldap'}