rewrite website

This commit is contained in:
bytedream committed 2025-10-13 21:04:21 +02:00
1 parent a6d910f56a
commit 32f28e5324
263 files changed
+17904 -14451

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import { ActionError, defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { db } from '@db/database.ts';
import { getJavaUuid } from '@util/minecraft.ts';
import { getSetting, SettingKey } from '@util/settings.ts';
import { sendWebhook, WebhookAction } from '@util/webhook.ts';
export const signup = {
signup: defineAction({
input: z.object({
firstname: z.string().trim().min(2),
lastname: z.string().trim().min(2),
birthday: z
.string()
.date()
// this will be inaccurate as it is evaluated only once
.max(Date.now() - 1000 * 60 * 60 * 24 * 365 * 6),
phone: z.string().trim().nullable(),
username: z.string().trim(),
edition: z.enum(['java', 'bedrock'])
}),
handler: async (input) => {
// check if signup is allowed
if (!(await getSetting(db, SettingKey.SignupEnabled))) {
throw new ActionError({
code: 'FORBIDDEN',
message: 'Die Anmeldung ist derzeit deaktiviert'
});
}
// check if the user were already signed up
if (await db.getUserByUsername({ username: input.username })) {
throw new ActionError({
code: 'CONFLICT',
message: 'Du hast dich bereits registriert'
});
}
let uuid;
try {
uuid = await getJavaUuid(input.username);
} catch (_) {
throw new ActionError({
code: 'NOT_FOUND',
message: `Es wurde kein Minecraft Java Account mit dem Username ${input.username} gefunden`
});
}
// check if user is blocked
if (uuid) {
const blockedUser = await db.getBlockedUserByUuid({ uuid: uuid });
if (blockedUser) {
throw new ActionError({
code: 'FORBIDDEN',
message: 'Du bist für die Registrierung gesperrt'
});
}
}
await db.addUser({
firstname: input.firstname,
lastname: input.lastname,
birthday: input.birthday,
telephone: input.phone,
username: input.username,
edition: input.edition,
uuid: uuid
});
sendWebhook(WebhookAction.Signup, {
firstname: input.firstname,
lastname: input.lastname,
birthday: new Date(input.birthday).toISOString().slice(0, 10),
telephone: input.phone,
username: input.username,
edition: input.edition
});
}
})
};