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';
|
2023-11-19 00:47:12 +00:00
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
|
|
|
import { config, user } from '$lib/stores';
|
2023-11-19 05:41:43 +00:00
|
|
|
import { onMount } from 'svelte';
|
2023-11-19 00:47:12 +00:00
|
|
|
import toast from 'svelte-french-toast';
|
|
|
|
|
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);
|
2023-11-20 01:47:07 +00:00
|
|
|
toast.success(`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>
|
|
|
|
|
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">
|
|
|
|
<img src="/ollama.png" class=" w-8" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class=" bg-white 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
|
|
|
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class="w-full max-w-lg px-10 md:px-16 bg-white min-h-screen flex flex-col">
|
2023-11-19 00:47:12 +00:00
|
|
|
<div class=" my-auto pb-10 w-full">
|
|
|
|
<form
|
|
|
|
class=" flex flex-col justify-center"
|
|
|
|
on:submit|preventDefault={() => {
|
2023-12-26 19:22:09 +00:00
|
|
|
submitHandler();
|
2023-11-19 00:47:12 +00:00
|
|
|
}}
|
|
|
|
>
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class=" text-xl md:text-2xl font-bold">
|
2023-11-19 00:47:12 +00:00
|
|
|
{mode === 'signin' ? 'Sign in' : 'Sign up'} to Ollama Web UI
|
|
|
|
</div>
|
|
|
|
|
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>
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class=" text-sm font-semibold text-left mb-1">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">
|
|
|
|
<div class=" text-sm font-semibold text-left mb-1">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>
|
2023-12-26 19:22:09 +00:00
|
|
|
<div class=" text-sm font-semibold text-left mb-1">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>
|