Profile: Add firstname field to users
This commit is contained in:
@ -7,6 +7,7 @@ export interface Graphic {
|
|||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
firstname: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
avatar_url?: string;
|
avatar_url?: string;
|
||||||
admin: boolean;
|
admin: boolean;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
TeamCard,
|
TeamCard,
|
||||||
RaceCard,
|
RaceCard,
|
||||||
SubstitutionCard,
|
SubstitutionCard,
|
||||||
|
NameIcon,
|
||||||
} from "$lib/components";
|
} from "$lib/components";
|
||||||
import { get_avatar_preview_event_handler } from "$lib/image";
|
import { get_avatar_preview_event_handler } from "$lib/image";
|
||||||
|
|
||||||
@ -151,13 +152,15 @@
|
|||||||
<!-- Data Drawer -->
|
<!-- Data Drawer -->
|
||||||
<!-- Data Drawer -->
|
<!-- Data Drawer -->
|
||||||
<div class="flex flex-col gap-2 p-2 pt-3">
|
<div class="flex flex-col gap-2 p-2 pt-3">
|
||||||
<Button href="/data/raceresult" onclick={close_drawer} color="surface" width="w-full"
|
<Button href="/data/raceresults" onclick={close_drawer} color="surface" width="w-full">
|
||||||
>Race Results
|
Race Results
|
||||||
|
</Button>
|
||||||
|
<Button href="/data/season/teams" onclick={close_drawer} color="surface" width="w-full">
|
||||||
|
Season
|
||||||
|
</Button>
|
||||||
|
<Button href="/data/users" onclick={close_drawer} color="surface" width="w-full">
|
||||||
|
Users
|
||||||
</Button>
|
</Button>
|
||||||
<Button href="/data/season/teams" onclick={close_drawer} color="surface" width="w-full"
|
|
||||||
>Season</Button
|
|
||||||
>
|
|
||||||
<Button href="/data/user" onclick={close_drawer} color="surface" width="w-full">Users</Button>
|
|
||||||
</div>
|
</div>
|
||||||
{:else if $drawerStore.id === "login_drawer"}
|
{:else if $drawerStore.id === "login_drawer"}
|
||||||
<!-- Login Drawer -->
|
<!-- Login Drawer -->
|
||||||
@ -168,22 +171,26 @@
|
|||||||
<form method="POST" class="contents">
|
<form method="POST" class="contents">
|
||||||
<!-- Supply the pathname so the form can redirect to the current page. -->
|
<!-- Supply the pathname so the form can redirect to the current page. -->
|
||||||
<input type="hidden" name="redirect_url" value={$page.url.pathname} />
|
<input type="hidden" name="redirect_url" value={$page.url.pathname} />
|
||||||
<Input name="username" placeholder="Username" autocomplete="username" required
|
<Input name="username" placeholder="Username" autocomplete="username" required>
|
||||||
><UserIcon />
|
<UserIcon />
|
||||||
</Input>
|
</Input>
|
||||||
<Input name="password" type="password" placeholder="Password" autocomplete="off" required
|
<Input name="firstname" placeholder="First Name (leave empty for login)" autocomplete="off">
|
||||||
><PasswordIcon />
|
<NameIcon />
|
||||||
|
</Input>
|
||||||
|
<Input name="password" type="password" placeholder="Password" autocomplete="off" required>
|
||||||
|
<PasswordIcon />
|
||||||
</Input>
|
</Input>
|
||||||
<div class="flex justify-end gap-2">
|
<div class="flex justify-end gap-2">
|
||||||
<Button formaction="/profile?/login" onclick={close_drawer} color="tertiary" submit
|
<Button formaction="/profile?/login" onclick={close_drawer} color="tertiary" submit>
|
||||||
>Login
|
Login
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
formaction="/profile?/create_profile"
|
formaction="/profile?/create_profile"
|
||||||
onclick={close_drawer}
|
onclick={close_drawer}
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
submit
|
submit
|
||||||
>Register
|
>
|
||||||
|
Register
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -206,6 +213,14 @@
|
|||||||
>
|
>
|
||||||
<UserIcon />
|
<UserIcon />
|
||||||
</Input>
|
</Input>
|
||||||
|
<Input
|
||||||
|
name="firstname"
|
||||||
|
value={data.user.firstname}
|
||||||
|
placeholder="First Name"
|
||||||
|
autocomplete="off"
|
||||||
|
>
|
||||||
|
<NameIcon />
|
||||||
|
</Input>
|
||||||
<FileDropzone
|
<FileDropzone
|
||||||
name="avatar"
|
name="avatar"
|
||||||
onchange={get_avatar_preview_event_handler("user_avatar_preview")}
|
onchange={get_avatar_preview_event_handler("user_avatar_preview")}
|
||||||
|
@ -7,11 +7,12 @@ import { AVATAR_HEIGHT, AVATAR_WIDTH } from "$lib/config";
|
|||||||
export const actions = {
|
export const actions = {
|
||||||
create_profile: async ({ request, locals }): Promise<void> => {
|
create_profile: async ({ request, locals }): Promise<void> => {
|
||||||
const data: FormData = form_data_clean(await request.formData());
|
const data: FormData = form_data_clean(await request.formData());
|
||||||
form_data_ensure_keys(data, ["username", "password", "redirect_url"]);
|
form_data_ensure_keys(data, ["username", "firstname", "password", "redirect_url"]);
|
||||||
|
|
||||||
// Confirm password lol
|
// Confirm password lol
|
||||||
await locals.pb.collection("users").create({
|
await locals.pb.collection("users").create({
|
||||||
username: data.get("username")?.toString(),
|
username: data.get("username")?.toString(),
|
||||||
|
firstname: data.get("firstname")?.toString(),
|
||||||
password: data.get("password")?.toString(),
|
password: data.get("password")?.toString(),
|
||||||
passwordConfirm: data.get("password")?.toString(),
|
passwordConfirm: data.get("password")?.toString(),
|
||||||
admin: false,
|
admin: false,
|
||||||
@ -22,6 +23,7 @@ export const actions = {
|
|||||||
.collection("users")
|
.collection("users")
|
||||||
.authWithPassword(data.get("username")?.toString(), data.get("password")?.toString());
|
.authWithPassword(data.get("username")?.toString(), data.get("password")?.toString());
|
||||||
|
|
||||||
|
// The current page is sent with the form, redirect to that page
|
||||||
redirect(303, data.get("redirect_url")?.toString() ?? "/");
|
redirect(303, data.get("redirect_url")?.toString() ?? "/");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user