|
|
@ -1,8 +1,10 @@
|
|
|
|
<script lang="ts">
|
|
|
|
<script lang="ts">
|
|
|
|
import { account, user } from '$lib/appwrite'
|
|
|
|
import { account, user } from '$lib/appwrite'
|
|
|
|
import Loading from '$lib/components/Common/Loading.svelte'
|
|
|
|
import Loading from '$lib/components/Common/Loading.svelte'
|
|
|
|
|
|
|
|
import Button from '$lib/components/erant/Button.svelte'
|
|
|
|
import { navigate } from '$lib/router'
|
|
|
|
import { navigate } from '$lib/router'
|
|
|
|
import Error from '$root/src/__error.svelte'
|
|
|
|
import { getErrorMessage } from '$lib/utils/appwrite/authorizationErrors'
|
|
|
|
|
|
|
|
import { getUserByErantId } from '$lib/utils/database/users'
|
|
|
|
import { ID } from 'appwrite'
|
|
|
|
import { ID } from 'appwrite'
|
|
|
|
import { Helper, Checkbox } from 'flowbite-svelte'
|
|
|
|
import { Helper, Checkbox } from 'flowbite-svelte'
|
|
|
|
import HiddenInput from '../../lib/components/Inputs/Hidden_Input.svelte'
|
|
|
|
import HiddenInput from '../../lib/components/Inputs/Hidden_Input.svelte'
|
|
|
@ -17,18 +19,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
let state: 'email-sent' | 'register' | 'loading' = 'register'
|
|
|
|
let state: 'email-sent' | 'register' | 'loading' = 'register'
|
|
|
|
let error: string | null = null
|
|
|
|
let error: string | null = null
|
|
|
|
|
|
|
|
$: buttonCodition = name.length > 0 && email.length > 0 && password.length >= 8 && password === repeatPassword && erantId.length > 2
|
|
|
|
|
|
|
|
|
|
|
|
const register = async () => {
|
|
|
|
const register = async () => {
|
|
|
|
//if (password === repeatPassword || name.length < 8 || email.length < 8) throw new Error('conditions are not fine')
|
|
|
|
//if (password === repeatPassword || name.length < 8 || email.length < 8) throw new Error('conditions are not fine')
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
state = 'loading'
|
|
|
|
state = 'loading'
|
|
|
|
error = null
|
|
|
|
error = null
|
|
|
|
|
|
|
|
if (await getUserByErantId(erantId)) {
|
|
|
|
|
|
|
|
const err = new Error('fdjsaůl')
|
|
|
|
|
|
|
|
err['code'] = 1001
|
|
|
|
|
|
|
|
throw err
|
|
|
|
|
|
|
|
}
|
|
|
|
await account.create(ID.unique(), email, password, name)
|
|
|
|
await account.create(ID.unique(), email, password, name)
|
|
|
|
await account.createEmailSession(email, password)
|
|
|
|
await account.createEmailSession(email, password)
|
|
|
|
await account.createVerification(`${location.origin}/register/emailverification/${erantId}`)
|
|
|
|
await account.createVerification(`${location.origin}/register/emailverification/${erantId}`)
|
|
|
|
state = 'email-sent'
|
|
|
|
state = 'email-sent'
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
error = JSON.parse(JSON.stringify(err)).response.message
|
|
|
|
error = getErrorMessage(err.code)
|
|
|
|
state = 'register'
|
|
|
|
state = 'register'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,7 +52,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form">
|
|
|
|
<div class="form">
|
|
|
|
{#if error}
|
|
|
|
{#if error}
|
|
|
|
<Helper color="red">{error}</Helper>
|
|
|
|
<Helper class="ml-4" color="red">{error}</Helper>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
<div class="inform">
|
|
|
|
<div class="inform">
|
|
|
|
<input bind:value={name} type="text" placeholder="Name" autocomplete="full-name" required />
|
|
|
|
<input bind:value={name} type="text" placeholder="Name" autocomplete="full-name" required />
|
|
|
@ -53,21 +61,29 @@
|
|
|
|
<HiddenInput bind:value={password} placeholder="Password" />
|
|
|
|
<HiddenInput bind:value={password} placeholder="Password" />
|
|
|
|
<HiddenInput bind:value={repeatPassword} placeholder="Re-type password" />
|
|
|
|
<HiddenInput bind:value={repeatPassword} placeholder="Re-type password" />
|
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="flex items-center">
|
|
|
|
<input id="link-checkbox" type="checkbox" value="" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" required>
|
|
|
|
<input
|
|
|
|
<label for="link-checkbox" class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">I agree with the <a href="erant.cz/terms-and-conditions" class="text-blue-600 dark:text-blue-500 hover:underline">terms and conditions</a>,
|
|
|
|
id="link-checkbox"
|
|
|
|
<a href="erant.cz/privacy-policy" class="text-blue-600 dark:text-blue-500 hover:underline">privacy policy</a> and
|
|
|
|
type="checkbox"
|
|
|
|
<a href="erant.cz/cookie-policy" class="text-blue-600 dark:text-blue-500 hover:underline">Cookie Policy</a>, which this site uses.</label>
|
|
|
|
value=""
|
|
|
|
|
|
|
|
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
|
|
|
|
|
|
|
|
required
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label for="link-checkbox" class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"
|
|
|
|
|
|
|
|
>I agree with the <a href="erant.cz/terms-and-conditions" class="text-blue-600 dark:text-blue-500 hover:underline">terms and conditions</a>,
|
|
|
|
|
|
|
|
<a href="erant.cz/privacy-policy" class="text-blue-600 dark:text-blue-500 hover:underline">privacy policy</a> and
|
|
|
|
|
|
|
|
<a href="erant.cz/cookie-policy" class="text-blue-600 dark:text-blue-500 hover:underline">Cookie Policy</a>, which this site uses.</label
|
|
|
|
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button class="loginButton" on:click={() => register()}>
|
|
|
|
<Button class="w-full text-2xl" disabled={!buttonCodition} on:click={() => register()}>
|
|
|
|
{#if state === 'loading'}
|
|
|
|
{#if state === 'loading'}
|
|
|
|
<Loading class="text-white" />
|
|
|
|
<Loading class="text-white" />
|
|
|
|
{:else}
|
|
|
|
{:else}
|
|
|
|
Sign up
|
|
|
|
Sign up
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="continue_with">
|
|
|
|
<div class="continue_with">
|
|
|
|
<button on:click={() => account.createOAuth2Session('google', location.origin, `${location.origin}/register/failed`)}>
|
|
|
|
<button on:click={() => account.createOAuth2Session('google', location.origin, `${location.origin}/register/failed`)}>
|
|
|
|
<GoogleLogo />
|
|
|
|
<GoogleLogo />
|
|
|
|