rename direct signup hash to code
This commit is contained in:
1 parent
51b3b446eb
commit
f2ca4747a6
10 files changed
+41
-41
No files matched your search
@@ -29,12 +29,12 @@ export const signup = {
|
||||
phone: z.string().trim().nullable(),
|
||||
username: z.string().trim(),
|
||||
edition: z.enum(['java', 'bedrock']),
|
||||
hash: z.string().nullish()
|
||||
code: z.string().nullish()
|
||||
}),
|
||||
handler: async (input, context) => {
|
||||
// check if hash given and if so, if it's valid and nobody has already used it
|
||||
if (input.hash) {
|
||||
const directSignup = await db.getDirectSignupByHash({ hash: input.hash });
|
||||
// check if code given and if so, if it's valid and nobody has already used it
|
||||
if (input.code) {
|
||||
const directSignup = await db.getDirectSignupByCode({ code: input.code });
|
||||
|
||||
if (!directSignup) {
|
||||
throw new ActionError({
|
||||
@@ -84,8 +84,8 @@ export const signup = {
|
||||
uuid: uuid
|
||||
});
|
||||
|
||||
if (input.hash) {
|
||||
await tx.setDirectSignupUser({ hash: input.hash, userId: user.id });
|
||||
if (input.code) {
|
||||
await tx.setDirectSignupUser({ code: input.code, userId: user.id });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -154,12 +154,12 @@ export const user = {
|
||||
}),
|
||||
deleteDirectInvitation: defineAction({
|
||||
input: z.object({
|
||||
hash: z.string()
|
||||
code: z.string()
|
||||
}),
|
||||
handler: async (input, context) => {
|
||||
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
|
||||
|
||||
await db.deleteDirectSignup({ hash: input.hash });
|
||||
await db.deleteDirectSignup({ code: input.code });
|
||||
}
|
||||
}),
|
||||
directInvitations: defineAction({
|
||||
|
||||
@@ -41,5 +41,5 @@ export async function deleteDirectInvitation(directInvitation: DirectInvitation)
|
||||
return;
|
||||
}
|
||||
|
||||
deleteFromWritableArray(directInvitations, (i) => i.hash === directInvitation.hash);
|
||||
deleteFromWritableArray(directInvitations, (i) => i.code === directInvitation.code);
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
signupHash?: string;
|
||||
signupCode?: string;
|
||||
serverIp: string;
|
||||
discordLink: string;
|
||||
paypalLink: string;
|
||||
@@ -19,7 +19,7 @@
|
||||
onFinished: () => void;
|
||||
}
|
||||
|
||||
let { signupHash, serverIp, discordLink, paypalLink, teamspeakLink, startDate, onFinished }: Props = $props();
|
||||
let { signupCode, serverIp, discordLink, paypalLink, teamspeakLink, startDate, onFinished }: Props = $props();
|
||||
|
||||
let rulesAccepted = $state(false);
|
||||
let rulesOpen = $state(false);
|
||||
@@ -73,7 +73,7 @@
|
||||
phone: form.phone.value,
|
||||
username: form.username.value,
|
||||
edition: 'java',
|
||||
hash: signupHash
|
||||
code: signupCode
|
||||
});
|
||||
|
||||
submitting = false;
|
||||
@@ -256,7 +256,7 @@
|
||||
{paypalLink}
|
||||
{teamspeakLink}
|
||||
{startDate}
|
||||
newRegistrationAllowed={!signupHash}
|
||||
newRegistrationAllowed={!signupCode}
|
||||
onClose={() => {
|
||||
registration = null;
|
||||
onFinished();
|
||||
|
||||
@@ -8,10 +8,10 @@ interface Props {
|
||||
message: string;
|
||||
subMessage?: string;
|
||||
};
|
||||
signupHash?: string;
|
||||
signupCode?: string;
|
||||
}
|
||||
|
||||
const { signupDisabled, signupHash } = Astro.props;
|
||||
const { signupDisabled, signupCode } = Astro.props;
|
||||
---
|
||||
|
||||
<WebsiteLayout title="Anmeldung" footer={false}>
|
||||
@@ -22,7 +22,7 @@ const { signupDisabled, signupHash } = Astro.props;
|
||||
<div class="relative grid card w-11/12 xl:w-2/3 2xl:w-1/2 p-6 my-12 bg-base-100 shadow-lg h-min">
|
||||
<SignupFlow
|
||||
client:load
|
||||
{signupHash}
|
||||
{signupCode}
|
||||
serverIp={SERVER_IP}
|
||||
discordLink={DISCORD_LINK}
|
||||
paypalLink={PAYPAL_LINK}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import JavaSignup from './JavaSignup.svelte';
|
||||
|
||||
interface Props {
|
||||
signupHash?: string;
|
||||
signupCode?: string;
|
||||
serverIp: string;
|
||||
discordLink: string;
|
||||
paypalLink: string;
|
||||
@@ -13,7 +13,7 @@
|
||||
startDate: string;
|
||||
}
|
||||
|
||||
let { signupHash, serverIp, discordLink, paypalLink, teamspeakLink, startDate }: Props = $props();
|
||||
let { signupCode, serverIp, discordLink, paypalLink, teamspeakLink, startDate }: Props = $props();
|
||||
|
||||
type Step = 'java' | 'bedrock' | null;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<div class:hidden={step !== 'java'}>
|
||||
<JavaSignup
|
||||
{signupHash}
|
||||
{signupCode}
|
||||
{serverIp}
|
||||
{discordLink}
|
||||
{paypalLink}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS blocked_user (
|
||||
|
||||
-- direct signup
|
||||
CREATE TABLE IF NOT EXISTS direct_signup (
|
||||
hash CHAR(255) NOT NULL UNIQUE,
|
||||
code CHAR(255) NOT NULL UNIQUE,
|
||||
user_id INT,
|
||||
FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
+3
-3
@@ -125,8 +125,8 @@ import {
|
||||
deleteDirectSignup,
|
||||
type DeleteDirectSignupReq,
|
||||
directSignup,
|
||||
getDirectSignupByHash,
|
||||
type GetDirectSignupByHashReq,
|
||||
getDirectSignupByCode,
|
||||
type GetDirectSignupByCodeReq,
|
||||
getDirectSignups,
|
||||
type GetDirectSignupsReq,
|
||||
setDirectSignupUser,
|
||||
@@ -211,7 +211,7 @@ export class Database {
|
||||
setDirectSignupUser = (values: SetDirectSignupUserReq) => setDirectSignupUser(this.db, values);
|
||||
deleteDirectSignup = (values: DeleteDirectSignupReq) => deleteDirectSignup(this.db, values);
|
||||
getDirectSignups = (values: GetDirectSignupsReq) => getDirectSignups(this.db, values);
|
||||
getDirectSignupByHash = (values: GetDirectSignupByHashReq) => getDirectSignupByHash(this.db, values);
|
||||
getDirectSignupByCode = (values: GetDirectSignupByCodeReq) => getDirectSignupByCode(this.db, values);
|
||||
|
||||
/* report */
|
||||
addReport = (values: AddReportReq) => addReport(this.db, values);
|
||||
|
||||
@@ -8,35 +8,35 @@ import { BASE_HOST, BASE_PATH } from 'astro:env/server';
|
||||
type Database = MySql2Database<{ directSignup: typeof directSignup }>;
|
||||
|
||||
export const directSignup = mysqlTable('direct_signup', {
|
||||
hash: varchar('hash', { length: 255 }).unique().notNull(),
|
||||
code: varchar('code', { length: 255 }).unique().notNull(),
|
||||
userId: int('user_id').references(() => user.id)
|
||||
});
|
||||
|
||||
export type AddDirectSignupReq = {};
|
||||
|
||||
export type SetDirectSignupUserReq = {
|
||||
hash: string;
|
||||
code: string;
|
||||
userId: number;
|
||||
};
|
||||
|
||||
export type DeleteDirectSignupReq = {
|
||||
hash: string;
|
||||
code: string;
|
||||
};
|
||||
|
||||
export type GetDirectSignupsReq = {};
|
||||
|
||||
export type GetDirectSignupByHashReq = {
|
||||
hash: string;
|
||||
export type GetDirectSignupByCodeReq = {
|
||||
code: string;
|
||||
};
|
||||
|
||||
export async function addDirectSignup(db: Database, _values: AddDirectSignupReq) {
|
||||
const hash = generateRandomString(16);
|
||||
const code = generateRandomString(16);
|
||||
|
||||
await db.insert(directSignup).values({
|
||||
hash: hash
|
||||
code: code
|
||||
});
|
||||
|
||||
return { hash: hash, url: `${BASE_HOST}/${BASE_PATH}/signup/${hash}` };
|
||||
return { code: code, url: `${BASE_HOST}/${BASE_PATH}/signup/${code}` };
|
||||
}
|
||||
|
||||
export async function setDirectSignupUser(db: Database, values: SetDirectSignupUserReq) {
|
||||
@@ -45,34 +45,34 @@ export async function setDirectSignupUser(db: Database, values: SetDirectSignupU
|
||||
.set({
|
||||
userId: values.userId
|
||||
})
|
||||
.where(eq(directSignup.hash, values.hash));
|
||||
.where(eq(directSignup.code, values.code));
|
||||
}
|
||||
|
||||
export async function deleteDirectSignup(db: Database, values: DeleteDirectSignupReq) {
|
||||
return db.delete(directSignup).where(eq(directSignup.hash, values.hash));
|
||||
return db.delete(directSignup).where(eq(directSignup.code, values.code));
|
||||
}
|
||||
|
||||
export async function getDirectSignups(db: Database, _values: GetDirectSignupsReq) {
|
||||
const directSignups = await db
|
||||
.select({
|
||||
hash: directSignup.hash,
|
||||
code: directSignup.code,
|
||||
user: user
|
||||
})
|
||||
.from(directSignup)
|
||||
.leftJoin(user, eq(directSignup.userId, user.id));
|
||||
|
||||
return directSignups.map((d) => ({ ...d, url: `${BASE_PATH}/signup/${d.hash}` }));
|
||||
return directSignups.map((d) => ({ ...d, url: `${BASE_PATH}/signup/${d.code}` }));
|
||||
}
|
||||
|
||||
export async function getDirectSignupByHash(db: Database, values: GetDirectSignupByHashReq) {
|
||||
export async function getDirectSignupByCode(db: Database, values: GetDirectSignupByCodeReq) {
|
||||
const directSignups = await db
|
||||
.select({
|
||||
hash: directSignup.hash,
|
||||
code: directSignup.code,
|
||||
user: user
|
||||
})
|
||||
.from(directSignup)
|
||||
.leftJoin(user, eq(directSignup.userId, user.id))
|
||||
.where(eq(directSignup.hash, values.hash))
|
||||
.where(eq(directSignup.code, values.code))
|
||||
.limit(1);
|
||||
|
||||
return directSignups[0] ?? null;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
import { db } from '@db/database.ts';
|
||||
import Signup from '@app/website/signup/Signup.astro';
|
||||
|
||||
const { hash } = Astro.params;
|
||||
const { code } = Astro.params;
|
||||
|
||||
const directSignup = await db.getDirectSignupByHash({ hash: hash! });
|
||||
const directSignup = await db.getDirectSignupByCode({ code: code! });
|
||||
if (!directSignup) return new Response(null, { status: 404 });
|
||||
---
|
||||
|
||||
<Signup
|
||||
signupHash={hash}
|
||||
signupCode={code}
|
||||
signupDisabled={
|
||||
directSignup.user
|
||||
? {
|
||||
Reference in new issue
Block a user