mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 21:42:58 +00:00
refac
This commit is contained in:
parent
75b169e11d
commit
547682c674
@ -2216,16 +2216,17 @@ async def get_app_config(request: Request):
|
||||
if data is not None and "id" in data:
|
||||
user = Users.get_user_by_id(data["id"])
|
||||
|
||||
user_count = 0
|
||||
onboarding = False
|
||||
if user is None:
|
||||
user_count = Users.get_num_users()
|
||||
onboarding = user_count == 0
|
||||
|
||||
return {
|
||||
**({"onboarding": True} if onboarding else {}),
|
||||
"status": True,
|
||||
"name": WEBUI_NAME,
|
||||
"version": VERSION,
|
||||
"default_locale": str(DEFAULT_LOCALE),
|
||||
**({"onboarding": True} if user_count is 0 else {}),
|
||||
"oauth": {
|
||||
"providers": {
|
||||
name: config.get("name", name)
|
||||
|
@ -27,7 +27,6 @@
|
||||
let password = '';
|
||||
|
||||
let ldapUsername = '';
|
||||
let ldapPassword = '';
|
||||
|
||||
const setSessionUser = async (sessionUser) => {
|
||||
if (sessionUser) {
|
||||
@ -64,6 +63,14 @@
|
||||
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 () => {
|
||||
if (mode === 'ldap') {
|
||||
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 () => {
|
||||
if (!$page.url.hash) {
|
||||
return;
|
||||
@ -113,6 +112,7 @@
|
||||
await goto('/');
|
||||
}
|
||||
await checkOauthCallback();
|
||||
|
||||
loaded = true;
|
||||
if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) {
|
||||
await signInHandler();
|
||||
@ -175,7 +175,8 @@
|
||||
<div class=" my-auto pb-10 w-full dark:text-gray-100">
|
||||
<form
|
||||
class=" flex flex-col justify-center"
|
||||
on:submit|preventDefault={() => {
|
||||
on:submit={(e) => {
|
||||
e.preventDefault();
|
||||
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"
|
||||
type="submit"
|
||||
>
|
||||
{($config?.onboarding ?? false)
|
||||
? $i18n.t('Authenticate as Admin')
|
||||
: $i18n.t('Authenticate')}
|
||||
{$i18n.t('Authenticate')}
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
@ -406,6 +405,7 @@
|
||||
<div class="mt-2">
|
||||
<button
|
||||
class="flex justify-center items-center text-xs w-full text-center underline"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
if (mode === 'ldap')
|
||||
mode = ($config?.onboarding ?? false) ? 'signup' : 'signin';
|
||||
|
Loading…
Reference in New Issue
Block a user