fix #73

Merged
Ota-Prokopec merged 1 commits from otafix into master 2023-03-14 17:36:58 +00:00
6 changed files with 52 additions and 12 deletions
Showing only changes of commit 21cb4e4da7 - Show all commits

View File

@ -12,7 +12,7 @@
let isMounted = false
$: isReady = $localeLoading === false && $authLoading === false && isMounted
$: if (isReady && $user?.emailVerification) {
$: if (isReady && !$user?.emailVerification) {
console.log('change')
if (!location.pathname.startsWith('/login') && !location.pathname.startsWith('/register')) {

View File

@ -0,0 +1,10 @@
<script lang="ts">
export let disabled: boolean = false
let className = ''
export { className as class }
</script>
<button {disabled} class={`bg-blue-500 rounded-xl text-white p-4 ${!disabled ? '' : 'bg-gray-500 text-white cursor-default'} ${className}`} on:click>
<slot />
</button>

View File

@ -0,0 +1,8 @@
export const errors = {
1001: 'Nickname is already taken',
409: 'A user with the same email already is in Erant',
}
export const getErrorMessage = (code: number) => {
return errors[code]
}

View File

@ -0,0 +1,6 @@
import { databases } from '$lib/appwrite'
import { Query } from 'appwrite'
export const getUserByErantId = async (erantId: string) => {
return (await databases.listDocuments('63ded6c18e8493bffc83', 'Users', [Query.equal('erantId', erantId)])).documents[0]
}

View File

@ -12,7 +12,7 @@
userName: $user.name,
userId: $user.$id,
},
[Permission.delete(Role.user($user.$id)), Permission.update(Role.user($user.$id))],
[Permission.delete(Role.user($user.$id)), Permission.update(Role.user($user.$id)), Permission.read(Role.users('verified'))],
)
navigate('/')
})()

View File

@ -1,8 +1,10 @@
<script lang="ts">
import { account, user } from '$lib/appwrite'
import Loading from '$lib/components/Common/Loading.svelte'
import Button from '$lib/components/erant/Button.svelte'
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 { Helper, Checkbox } from 'flowbite-svelte'
import HiddenInput from '../../lib/components/Inputs/Hidden_Input.svelte'
@ -17,18 +19,24 @@
let state: 'email-sent' | 'register' | 'loading' = 'register'
let error: string | null = null
$: buttonCodition = name.length > 0 && email.length > 0 && password.length >= 8 && password === repeatPassword && erantId.length > 2
const register = async () => {
//if (password === repeatPassword || name.length < 8 || email.length < 8) throw new Error('conditions are not fine')
try {
state = 'loading'
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.createEmailSession(email, password)
await account.createVerification(`${location.origin}/register/emailverification/${erantId}`)
state = 'email-sent'
} catch (err) {
error = JSON.parse(JSON.stringify(err)).response.message
error = getErrorMessage(err.code)
state = 'register'
}
}
@ -44,7 +52,7 @@
<div class="form">
{#if error}
<Helper color="red">{error}</Helper>
<Helper class="ml-4" color="red">{error}</Helper>
{/if}
<div class="inform">
<input bind:value={name} type="text" placeholder="Name" autocomplete="full-name" required />
@ -53,18 +61,26 @@
<HiddenInput bind:value={password} placeholder="Password" />
<HiddenInput bind:value={repeatPassword} placeholder="Re-type password" />
<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>
<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>,
<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
/>
<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>
<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>
<button class="loginButton" on:click={() => register()}>
<Button class="w-full text-2xl" disabled={!buttonCodition} on:click={() => register()}>
{#if state === 'loading'}
<Loading class="text-white" />
{:else}
Sign up
{/if}
</button>
</Button>
</div>
</div>