mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-12 13:59:08 +02:00
implement invite code generation
This commit is contained in:
40
apps/app/package-lock.json
generated
40
apps/app/package-lock.json
generated
@@ -16,7 +16,8 @@
|
||||
"arctic": "^3.3.0",
|
||||
"neo4j-driver": "^5.28.1",
|
||||
"openapi-fetch": "^0.13.5",
|
||||
"pikaday": "^1.8.2"
|
||||
"pikaday": "^1.8.2",
|
||||
"uuid": "^11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@chromatic-com/storybook": "^3.2.4",
|
||||
@@ -2806,6 +2807,20 @@
|
||||
"storybook": "^8.5.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/addon-actions/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/addon-backgrounds": {
|
||||
"version": "8.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@storybook/addon-backgrounds/-/addon-backgrounds-8.5.6.tgz",
|
||||
@@ -3397,6 +3412,20 @@
|
||||
"storybook": "^8.5.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/sveltekit/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/test": {
|
||||
"version": "8.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@storybook/test/-/test-8.5.6.tgz",
|
||||
@@ -10289,17 +10318,16 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"dev": true,
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
|
||||
"integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
"uuid": "dist/esm/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/v8-compile-cache": {
|
||||
|
@@ -67,6 +67,7 @@
|
||||
"arctic": "^3.3.0",
|
||||
"neo4j-driver": "^5.28.1",
|
||||
"openapi-fetch": "^0.13.5",
|
||||
"pikaday": "^1.8.2"
|
||||
"pikaday": "^1.8.2",
|
||||
"uuid": "^11.1.0"
|
||||
}
|
||||
}
|
||||
|
@@ -28,9 +28,11 @@
|
||||
field: keyof components['schemas']['PersonProperties'],
|
||||
value: any
|
||||
) {
|
||||
console.log('Draft person change:', field, value);
|
||||
draftPerson[field] = value;
|
||||
console.log('Draft person:', draftPerson);
|
||||
if (field === 'invite_code') {
|
||||
save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
@@ -63,8 +65,7 @@
|
||||
const data = (await response.json()) as {
|
||||
person?: components['schemas']['Person'];
|
||||
};
|
||||
console.log('Person data updated successfully:', draftPerson);
|
||||
console.log('Person data saved successfully:', data);
|
||||
|
||||
return;
|
||||
} else {
|
||||
const errorDetails = await response.json();
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import type { components } from '$lib/api/api.gen';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import {
|
||||
male,
|
||||
female,
|
||||
@@ -18,7 +19,10 @@
|
||||
mothers_first_name,
|
||||
mothers_last_name,
|
||||
profile_picture,
|
||||
create_invite_code
|
||||
create_invite_code,
|
||||
|
||||
invite_code
|
||||
|
||||
} from '$lib/paraglide/messages';
|
||||
import { callMessageFunction } from '$lib/i18n';
|
||||
import type { MessageKeys } from '$lib/i18n';
|
||||
@@ -28,6 +32,7 @@
|
||||
};
|
||||
export let editorMode = false;
|
||||
export let onChange: (field: keyof components['schemas']['PersonProperties'], value: any) => void;
|
||||
let new_invite_code: string | undefined;
|
||||
|
||||
let birth_date: HTMLInputElement;
|
||||
let death_date: HTMLInputElement;
|
||||
@@ -174,7 +179,17 @@
|
||||
<p><strong>{id()}: </strong>{' ' + (person.id ?? '-')}</p>
|
||||
<p><strong>Limit: </strong>{' ' + (person.limit ?? '-')}</p>
|
||||
{#if editorMode && (person.google_id === undefined || person.google_id === null || person.google_id === '')}
|
||||
<button class="btn btn-soft btn-accent btn-m">{create_invite_code()}</button>
|
||||
{#if new_invite_code===undefined}
|
||||
<button class="btn btn-soft btn-accent btn-m" onclick={()=>{
|
||||
new_invite_code = uuidv4();
|
||||
person.invite_code = new_invite_code;
|
||||
onChange('invite_code',new_invite_code);
|
||||
}}>{create_invite_code()}</button>
|
||||
{:else}
|
||||
<p>
|
||||
<strong>{invite_code()}:</strong>{person.invite_code}
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -186,13 +186,15 @@ async function register(event: RequestEvent) {
|
||||
})
|
||||
});
|
||||
}
|
||||
const birth_date = data.get('birth_date');
|
||||
let birth_date = data.get('birth_date');
|
||||
if (birth_date === null || birth_date === '') {
|
||||
return fail(400, {
|
||||
message: missing_field({
|
||||
field: born()
|
||||
})
|
||||
});
|
||||
});
|
||||
}else {
|
||||
birth_date = birth_date.toString();
|
||||
}
|
||||
|
||||
const bbiological_sex = data.get('biological_sex');
|
||||
@@ -244,29 +246,69 @@ async function register(event: RequestEvent) {
|
||||
limit: StorageLimit
|
||||
};
|
||||
|
||||
let response = await client.POST('/person/google/{google_id}', {
|
||||
params: {
|
||||
data: parsedData,
|
||||
path: { google_id: google_id.toString() }
|
||||
},
|
||||
body: personP
|
||||
});
|
||||
|
||||
if (response.response.status !== 200) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + response.error?.msg
|
||||
});
|
||||
let invite_code = data.get('invite_code');
|
||||
if (invite_code !== null) {
|
||||
invite_code = invite_code.toString();
|
||||
}else {
|
||||
invite_code = '';
|
||||
}
|
||||
|
||||
if (response.data === undefined) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + 'No user data returned'
|
||||
let responseData :{
|
||||
Id?: number;
|
||||
ElementId?: string;
|
||||
Labels?: string[];
|
||||
Props?: components["schemas"]["PersonProperties"];
|
||||
} | undefined = undefined;
|
||||
if (!(invite_code.length > 0)){
|
||||
let response = await client.POST('/person/google/{google_id}', {
|
||||
params: {
|
||||
data: parsedData,
|
||||
path: { google_id: google_id.toString() }
|
||||
},
|
||||
body: personP
|
||||
});
|
||||
|
||||
if (response.response.status !== 200) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + response.error?.msg
|
||||
});
|
||||
}
|
||||
|
||||
if (response.data === undefined) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + 'No user data returned'
|
||||
});
|
||||
}
|
||||
responseData = response.data;
|
||||
}else {
|
||||
let response = await client.PATCH('/person/google/{google_id}', {
|
||||
params: {
|
||||
path: { google_id: google_id.toString() }
|
||||
},
|
||||
body: {
|
||||
invite_code: invite_code,
|
||||
person: personP
|
||||
},
|
||||
});
|
||||
if (response.response.status !== 200) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + response.error?.msg
|
||||
});
|
||||
}
|
||||
|
||||
if (response.data === undefined) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + 'No user data returned'
|
||||
});
|
||||
}
|
||||
responseData = response.data;
|
||||
}
|
||||
|
||||
if (response.data.Id === undefined) {
|
||||
if (responseData.Id === undefined) {
|
||||
return fail(400, {
|
||||
data: parsedData,
|
||||
message: failed_to_create_user() + 'No user ID returned'
|
||||
@@ -280,10 +322,10 @@ async function register(event: RequestEvent) {
|
||||
});
|
||||
}
|
||||
|
||||
const sessionToken = generateSessionToken(String(response.data.Id));
|
||||
const sessionToken = generateSessionToken(String(responseData.Id));
|
||||
const session = await createSession(
|
||||
sessionToken,
|
||||
response.data.Id,
|
||||
responseData.Id,
|
||||
event.platform.env.GH_SESSIONS
|
||||
);
|
||||
if (session === null) {
|
||||
|
@@ -16,7 +16,13 @@
|
||||
male,
|
||||
female,
|
||||
other,
|
||||
intersex
|
||||
intersex,
|
||||
|
||||
invite_code,
|
||||
|
||||
have_invite_code
|
||||
|
||||
|
||||
} from '$lib/paraglide/messages';
|
||||
import { onMount } from 'svelte';
|
||||
import { enhance } from '$app/forms';
|
||||
@@ -45,7 +51,7 @@
|
||||
birth_date_value.placeholder = '';
|
||||
},
|
||||
onSelect: function (date) {
|
||||
birth_date_value.value = date.toISOString();
|
||||
birth_date_value.value = date.toISOString().split('T')[0];
|
||||
}
|
||||
});
|
||||
// Clean up when component unmounts
|
||||
@@ -53,6 +59,11 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let showInviteInput = $state(false);
|
||||
function toggleInviteInput() {
|
||||
showInviteInput = !showInviteInput;
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -163,7 +174,23 @@
|
||||
id="mothers_first_name"
|
||||
placeholder={mothers_first_name()}
|
||||
/>
|
||||
<button class="btn btn-neutral mt-4">{register()}</button>
|
||||
<button type="button" class="btn btn-soft mt-4 max-w-xs" onclick={toggleInviteInput}>
|
||||
{have_invite_code()}
|
||||
</button>
|
||||
{#if showInviteInput}
|
||||
<div class="mt-4">
|
||||
<label class="fieldset-label" for="invite_code">Meghívókód</label>
|
||||
<input
|
||||
type="text"
|
||||
class="input input-bordered w-full"
|
||||
name="invite_code"
|
||||
id="invite_code"
|
||||
placeholder={invite_code()}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button class="btn btn-neutral mt-4 max-w-xs">{register()}</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user