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