2023-11-19 00:47:12 +00:00
|
|
|
<script>
|
|
|
|
import { goto } from '$app/navigation';
|
2023-12-26 19:22:09 +00:00
|
|
|
import { userSignIn, userSignUp } from '$lib/apis/auths';
|
2024-02-24 01:12:19 +00:00
|
|
|
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
|
|
|
import { WEBUI_NAME, config, user } from '$lib/stores';
|
2024-03-02 20:38:51 +00:00
|
|
|
import { onMount, getContext } from 'svelte';
|
2024-03-01 09:18:07 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2023-11-19 00:47:12 +00:00
|
|
|
|
2024-03-02 20:38:51 +00:00
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
2023-11-19 05:41:43 +00:00
|
|
|
let loaded = false;
|
2023-11-19 00:47:12 +00:00
|
|
|
let mode = 'signin';
|
|
|
|
|
|
|
|
let name = '';
|
|
|
|
let email = '';
|
|
|
|
let password = '';
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
const setSessionUser = async (sessionUser) => {
|
|
|
|
if (sessionUser) {
|
|
|
|
console.log(sessionUser);
|
2024-03-02 20:38:51 +00:00
|
|
|
toast.success($i18n.t(`You're now logged in.`));
|
2023-12-26 19:22:09 +00:00
|
|
|
localStorage.token = sessionUser.token;
|
|
|
|
await user.set(sessionUser);
|
2023-11-19 00:47:12 +00:00
|
|
|
goto('/');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
const signInHandler = async () => {
|
|
|
|
const sessionUser = await userSignIn(email, password).catch((error) => {
|
|
|
|
toast.error(error);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
await setSessionUser(sessionUser);
|
|
|
|
};
|
|
|
|
|
2023-11-19 00:47:12 +00:00
|
|
|
const signUpHandler = async () => {
|
2023-12-26 19:22:09 +00:00
|
|
|
const sessionUser = await userSignUp(name, email, password).catch((error) => {
|
|
|
|
toast.error(error);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
await setSessionUser(sessionUser);
|
|
|
|
};
|
|
|
|
|
|
|
|
const submitHandler = async () => {
|
|
|
|
if (mode === 'signin') {
|
|
|
|
await signInHandler();
|
|
|
|
} else {
|
|
|
|
await signUpHandler();
|
2023-11-19 00:47:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-19 05:41:43 +00:00
|
|
|
onMount(async () => {
|
2023-12-26 19:22:09 +00:00
|
|
|
if ($user !== undefined) {
|
2023-11-19 05:41:43 +00:00
|
|
|
await goto('/');
|
|
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
});
|
2023-11-19 00:47:12 +00:00
|
|
|
</script>
|
|
|
|
|
2024-03-02 06:38:04 +00:00
|
|
|
<svelte:head>
|
|
|
|
<title>
|
|
|
|
{`${$WEBUI_NAME}`}
|
|
|
|
</title>
|
|
|
|
</svelte:head>
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
{#if loaded}
|
2023-11-19 00:47:12 +00:00
|
|
|
<div class="fixed m-10 z-50">
|
|
|
|
<div class="flex space-x-2">
|
|
|
|
<div class=" self-center">
|
2024-02-24 01:12:19 +00:00
|
|
|
<img src="{WEBUI_BASE_URL}/static/favicon.png" class=" w-8 rounded-full" alt="logo" />
|
2023-11-19 00:47:12 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-03-02 06:52:21 +00:00
|
|
|
<div class=" bg-white dark:bg-gray-900 min-h-screen w-full flex justify-center font-mona">
|
2023-12-26 19:22:09 +00:00
|
|
|
<!-- <div class="hidden lg:flex lg:flex-1 px-10 md:px-16 w-full bg-yellow-50 justify-center">
|
2023-11-19 00:47:12 +00:00
|
|
|
<div class=" my-auto pb-16 text-left">
|
|
|
|
<div>
|
|
|
|
<div class=" font-bold text-yellow-600 text-4xl">
|
|
|
|
Get up and running with <br />large language models, locally.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mt-2 text-yellow-600 text-xl">
|
|
|
|
Run Llama 2, Code Llama, and other models. Customize and create your own.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-26 19:22:09 +00:00
|
|
|
</div> -->
|
2023-11-19 00:47:12 +00:00
|
|
|
|
2024-03-02 06:52:21 +00:00
|
|
|
<div class="w-full sm:max-w-lg px-4 min-h-screen flex flex-col">
|
2023-11-19 00:47:12 +00:00
|
|
|
<div class=" my-auto pb-10 w-full">
|
|
|
|
<form
|
2024-03-02 06:52:21 +00:00
|
|
|
class=" flex flex-col justify-center bg-white py-6 sm:py-16 px-6 sm:px-16 rounded-2xl"
|
2023-11-19 00:47:12 +00:00
|
|
|
on:submit|preventDefault={() => {
|
2023-12-26 19:22:09 +00:00
|
|
|
submitHandler();
|
2023-11-19 00:47:12 +00:00
|
|
|
}}
|
|
|
|
>
|
2024-03-02 06:52:21 +00:00
|
|
|
<div class=" text-xl sm:text-2xl font-bold">
|
2024-02-24 01:12:19 +00:00
|
|
|
{mode === 'signin' ? 'Sign in' : 'Sign up'} to {$WEBUI_NAME}
|
2023-11-19 00:47:12 +00:00
|
|
|
</div>
|
|
|
|
|
2024-02-12 00:22:47 +00:00
|
|
|
{#if mode === 'signup'}
|
|
|
|
<div class=" mt-1 text-xs font-medium text-gray-500">
|
2024-02-24 01:12:19 +00:00
|
|
|
ⓘ {$WEBUI_NAME} does not make any external connections, and your data stays securely on
|
2024-02-12 01:57:56 +00:00
|
|
|
your locally hosted server.
|
2024-02-12 00:22:47 +00:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class="flex flex-col mt-4">
|
2023-11-19 00:47:12 +00:00
|
|
|
{#if mode === 'signup'}
|
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" text-sm font-semibold text-left mb-1">{$i18n.t('Name')}</div>
|
2023-11-19 00:47:12 +00:00
|
|
|
<input
|
|
|
|
bind:value={name}
|
|
|
|
type="text"
|
2023-12-26 19:22:09 +00:00
|
|
|
class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
|
2023-11-19 00:47:12 +00:00
|
|
|
autocomplete="name"
|
2023-12-26 19:22:09 +00:00
|
|
|
placeholder="Enter Your Full Name"
|
2023-11-19 00:47:12 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
2023-12-26 19:22:09 +00:00
|
|
|
|
|
|
|
<hr class=" my-3" />
|
2023-11-19 00:47:12 +00:00
|
|
|
{/if}
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class="mb-2">
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" text-sm font-semibold text-left mb-1">{$i18n.t('Email')}</div>
|
2023-11-19 00:47:12 +00:00
|
|
|
<input
|
|
|
|
bind:value={email}
|
|
|
|
type="email"
|
2023-12-26 19:22:09 +00:00
|
|
|
class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
|
2023-11-19 00:47:12 +00:00
|
|
|
autocomplete="email"
|
2023-12-26 19:22:09 +00:00
|
|
|
placeholder="Enter Your Email"
|
2023-11-19 00:47:12 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" text-sm font-semibold text-left mb-1">{$i18n.t('Password')}</div>
|
2023-11-19 00:47:12 +00:00
|
|
|
<input
|
|
|
|
bind:value={password}
|
|
|
|
type="password"
|
2023-12-26 19:22:09 +00:00
|
|
|
class=" border px-4 py-2.5 rounded-2xl w-full text-sm"
|
|
|
|
placeholder="Enter Your Password"
|
2023-11-19 00:47:12 +00:00
|
|
|
autocomplete="current-password"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class="mt-5">
|
2023-11-19 00:47:12 +00:00
|
|
|
<button
|
2023-12-26 19:22:09 +00:00
|
|
|
class=" bg-gray-900 hover:bg-gray-800 w-full rounded-full text-white font-semibold text-sm py-3 transition"
|
2023-11-19 00:47:12 +00:00
|
|
|
type="submit"
|
|
|
|
>
|
|
|
|
{mode === 'signin' ? 'Sign In' : 'Create Account'}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div class=" mt-4 text-sm text-center">
|
|
|
|
{mode === 'signin' ? `Don't have an account?` : `Already have an account?`}
|
|
|
|
|
|
|
|
<button
|
|
|
|
class=" font-medium underline"
|
|
|
|
type="button"
|
|
|
|
on:click={() => {
|
|
|
|
if (mode === 'signin') {
|
|
|
|
mode = 'signup';
|
|
|
|
} else {
|
|
|
|
mode = 'signin';
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{mode === 'signin' ? `Sign up` : `Sign In`}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2023-11-19 08:13:59 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.font-mona {
|
|
|
|
font-family: 'Mona Sans';
|
|
|
|
}
|
|
|
|
</style>
|