diff --git a/src/app/jams/(manip)/delete/judgement/[judgementid]/components/form.tsx b/src/app/jams/(manip)/delete/judgement/[judgementid]/components/form.tsx
index 2d8a759..703f508 100644
--- a/src/app/jams/(manip)/delete/judgement/[judgementid]/components/form.tsx
+++ b/src/app/jams/(manip)/delete/judgement/[judgementid]/components/form.tsx
@@ -26,6 +26,6 @@ export function Form({judgementID, contentID}:{judgementID:string, contentID:str
-
+
);
}
\ No newline at end of file
diff --git a/src/app/jams/(manip)/delete/user/[userid]/components/form.tsx b/src/app/jams/(manip)/delete/user/[userid]/components/form.tsx
new file mode 100644
index 0000000..360c516
--- /dev/null
+++ b/src/app/jams/(manip)/delete/user/[userid]/components/form.tsx
@@ -0,0 +1,33 @@
+'use client';
+import React from "react";
+import { ErrorMessage, useFormik } from "formik";
+import { useRouter } from "next/navigation";
+import { ConditionalNull } from "@/components/utility/Conditional";
+import { JSONContentTable, JSONJudgementTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
+
+export function Form({userID}:{userID:string}) {
+ const router = useRouter();
+ const formik = useFormik({
+ initialValues: {},
+ onSubmit: async (values) => {
+ const submitRequest = await fetch(`/jams/api/users/${userID}`, {
+ method: "DELETE"
+ });
+
+ if (submitRequest.ok) {
+ router.push(`/jams/`);
+ } else {
+ formik.setSubmitting(false);
+ }
+ },
+ });
+
+ return (
+
+ );
+}
\ No newline at end of file
diff --git a/src/app/jams/(manip)/delete/user/[userid]/page.tsx b/src/app/jams/(manip)/delete/user/[userid]/page.tsx
new file mode 100644
index 0000000..e7f94a2
--- /dev/null
+++ b/src/app/jams/(manip)/delete/user/[userid]/page.tsx
@@ -0,0 +1,67 @@
+
+import { Conditional, ConditionalNull } from "@/components/utility/Conditional";
+import { MainLayout } from "@/layout/MainLayout/MainLayout";
+import { db } from "@/lib/mastoauth/kysely";
+import { JSONContentTable, JSONJamTable, JSONJudgementTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
+import { cookies } from "next/headers";
+import { notFound, redirect } from "next/navigation";
+import { Form } from "./components/form";
+
+export default async function Home({
+ params
+}: {
+ params: {
+ userid: string
+ }
+}) {
+ const cookieStore = cookies();
+ const token = cookieStore.get('token')?.value;
+ let existingUser;
+ if (token != null) {
+ let existingToken = await db
+ .selectFrom('tokens')
+ .where('tokens.id', '=', token)
+ .select('owner')
+ .executeTakeFirst();
+
+ if (existingToken != null) {
+ existingUser = await db
+ .selectFrom('users')
+ .where('users.id', '=', existingToken.owner)
+ .selectAll()
+ .executeTakeFirst();
+ }
+ }
+
+ if (existingUser == null) return redirect("/jams/");
+
+ const userid = params.userid;
+
+ if (userid == null) return notFound();
+
+ // It's a JSONJamTable. I don't know why TS hates `number` => `string` conversion.
+ let editingUser = await db
+ .selectFrom('users')
+ .where('users.id', '=', userid)
+ .selectAll()
+ .executeTakeFirst() as unknown as JSONUserTable;
+
+ if (editingUser == null) return notFound();
+
+ if (!existingUser.admin && editingUser.id != existingUser.id) return (
+
+ Can't edit this user
+ You are not this user
+
+ );
+
+ return (
+
+ Deleting user {editingUser.username}@{editingUser.instance}
+
+ Logged in as {existingUser?.username}@{existingUser?.instance}
+
+
+
+ )
+}
\ No newline at end of file
diff --git a/src/app/jams/(manip)/edit/user/[userid]/components/form.tsx b/src/app/jams/(manip)/edit/user/[userid]/components/form.tsx
new file mode 100644
index 0000000..66655f9
--- /dev/null
+++ b/src/app/jams/(manip)/edit/user/[userid]/components/form.tsx
@@ -0,0 +1,78 @@
+'use client';
+import React from "react";
+import { ErrorMessage, useFormik } from "formik";
+import { useRouter } from "next/navigation";
+import { ConditionalNull } from "@/components/utility/Conditional";
+import { JSONContentTable, JSONJudgementTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
+
+export function Form({userID, preset}:{userID:string, preset:JSONUserTable}) {
+ const router = useRouter();
+ const formik = useFormik({
+ initialValues: {
+ admin: preset.admin,
+ banned: preset.banned,
+ },
+ onSubmit: async (values) => {
+ console.log(values);
+ const submitRequest = await fetch(`/jams/api/users/${userID}`, {
+ method: "PATCH",
+ body: JSON.stringify(values)
+ });
+
+ if (submitRequest.ok) {
+ router.push(`/jams/user/${userID}`);
+ } else {
+ formik.setSubmitting(false);
+ if (submitRequest.status == 400) {
+ let errors:string[]|null = null;
+ try {
+ errors = await submitRequest.json();
+ } catch (err) { }; // No body. Skill issue
+ if (errors == null) return;
+ let transformedErrors:{[key:string]:string} = {};
+ errors.forEach((string) => transformedErrors[string] = "Something's wrong here");
+ formik.setErrors(transformedErrors);
+ } else {
+ formik.setErrors({
+ admin: "Something went wrong..."
+ });
+ }
+ }
+ },
+ });
+
+ return (
+
+ );
+}
\ No newline at end of file
diff --git a/src/app/jams/(manip)/edit/user/[userid]/page.tsx b/src/app/jams/(manip)/edit/user/[userid]/page.tsx
new file mode 100644
index 0000000..c95e28a
--- /dev/null
+++ b/src/app/jams/(manip)/edit/user/[userid]/page.tsx
@@ -0,0 +1,67 @@
+
+import { Conditional, ConditionalNull } from "@/components/utility/Conditional";
+import { MainLayout } from "@/layout/MainLayout/MainLayout";
+import { db } from "@/lib/mastoauth/kysely";
+import { JSONContentTable, JSONJamTable, JSONJudgementTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
+import { cookies } from "next/headers";
+import { notFound, redirect } from "next/navigation";
+import { Form } from "./components/form";
+
+export default async function Home({
+ params
+}: {
+ params: {
+ userid: string
+ }
+}) {
+ const cookieStore = cookies();
+ const token = cookieStore.get('token')?.value;
+ let existingUser;
+ if (token != null) {
+ let existingToken = await db
+ .selectFrom('tokens')
+ .where('tokens.id', '=', token)
+ .select('owner')
+ .executeTakeFirst();
+
+ if (existingToken != null) {
+ existingUser = await db
+ .selectFrom('users')
+ .where('users.id', '=', existingToken.owner)
+ .selectAll()
+ .executeTakeFirst();
+ }
+ }
+
+ if (existingUser == null) return redirect("/jams/");
+
+ const userid = params.userid;
+
+ if (userid == null) return notFound();
+
+ // It's a JSONJamTable. I don't know why TS hates `number` => `string` conversion.
+ let editingUser = await db
+ .selectFrom('users')
+ .where('users.id', '=', userid)
+ .selectAll()
+ .executeTakeFirst() as unknown as JSONUserTable;
+
+ if (editingUser == null) return notFound();
+
+ if (!existingUser.admin) return (
+
+ Can't edit this user
+ You are not an admin
+
+ );
+
+ return (
+
+ Editing user {editingUser.username}@{editingUser.instance}
+
+ Logged in as {existingUser?.username}@{existingUser?.instance}
+
+
+
+ )
+}
\ No newline at end of file
diff --git a/src/app/jams/api/content/[content]/judgements/[judgement]/route.ts b/src/app/jams/api/content/[content]/judgements/[judgement]/route.ts
index ca9fdfa..33d0356 100644
--- a/src/app/jams/api/content/[content]/judgements/[judgement]/route.ts
+++ b/src/app/jams/api/content/[content]/judgements/[judgement]/route.ts
@@ -71,13 +71,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {content:st
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.judgement;
if (id == null) return new Response('', {
@@ -169,13 +173,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {content:s
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.judgement;
if (id == null) return new Response('', {
diff --git a/src/app/jams/api/content/[content]/judgements/route.ts b/src/app/jams/api/content/[content]/judgements/route.ts
index 0bab06b..41c3c6f 100644
--- a/src/app/jams/api/content/[content]/judgements/route.ts
+++ b/src/app/jams/api/content/[content]/judgements/route.ts
@@ -70,13 +70,17 @@ export async function POST(request: NextRequest, {params}: {params: {content: st
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select('id')
+ .select(['id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
let body;
try {
body = await request.json();
diff --git a/src/app/jams/api/content/[content]/route.ts b/src/app/jams/api/content/[content]/route.ts
index 686a444..fdcaa38 100644
--- a/src/app/jams/api/content/[content]/route.ts
+++ b/src/app/jams/api/content/[content]/route.ts
@@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {content:st
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.content;
if (id == null) return new Response('', {
@@ -126,13 +130,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {content:s
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.content;
if (id == null) return new Response('', {
diff --git a/src/app/jams/api/jams/[jam]/content/route.ts b/src/app/jams/api/jams/[jam]/content/route.ts
index 00fcd4f..3730592 100644
--- a/src/app/jams/api/jams/[jam]/content/route.ts
+++ b/src/app/jams/api/jams/[jam]/content/route.ts
@@ -75,13 +75,17 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select('id')
+ .select(['id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
let body;
try {
body = await request.json();
diff --git a/src/app/jams/api/jams/[jam]/route.ts b/src/app/jams/api/jams/[jam]/route.ts
index cdb5931..5b4f6da 100644
--- a/src/app/jams/api/jams/[jam]/route.ts
+++ b/src/app/jams/api/jams/[jam]/route.ts
@@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {jam:string
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.jam;
if (id == null) return new Response('', {
@@ -127,13 +131,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {jam:strin
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const id = params.jam;
if (id == null) return new Response('', {
diff --git a/src/app/jams/api/jams/route.ts b/src/app/jams/api/jams/route.ts
index f90fa09..21fcef2 100644
--- a/src/app/jams/api/jams/route.ts
+++ b/src/app/jams/api/jams/route.ts
@@ -41,13 +41,17 @@ export async function POST(request: NextRequest) {
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
if (!existingUser.admin) return new Response('you are NOT that guy.', {
status: 401
});
diff --git a/src/app/jams/api/users/[user]/route.ts b/src/app/jams/api/users/[user]/route.ts
index 525e67b..815f32a 100644
--- a/src/app/jams/api/users/[user]/route.ts
+++ b/src/app/jams/api/users/[user]/route.ts
@@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {user:strin
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const name = params.user;
if (name == null) return new Response('', {
@@ -86,9 +90,9 @@ export async function PATCH(request: NextRequest, {params}: {params: {user:strin
let res;
try {
res = await db
- .updateTable('jams')
+ .updateTable('users')
.set(newBody)
- .where('id', '=', updatingUser.id)
+ .where('users.id', '=', updatingUser.id)
.executeTakeFirstOrThrow();
} catch (err) {
return new Response('', {
@@ -123,13 +127,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {user:stri
let existingUser = await db
.selectFrom('users')
.where('users.id', '=', existingToken.owner)
- .select(['admin', 'id'])
+ .select(['admin', 'id', 'banned'])
.executeTakeFirst();
if (existingUser == null) return new Response('', {
status: 401
});
+ if (existingUser.banned) return new Response('U banned motherfucka!', {
+ status: 403
+ });
+
const name = params.user;
if (name == null) return new Response('', {
diff --git a/src/app/jams/user/[user]/page.tsx b/src/app/jams/user/[user]/page.tsx
index 1d41c93..187ab7f 100644
--- a/src/app/jams/user/[user]/page.tsx
+++ b/src/app/jams/user/[user]/page.tsx
@@ -21,6 +21,26 @@ export default async function Home({
}) {
const curDate = Date.now();
const curPage = parseInt(searchParams?.until) || curDate;
+
+ const cookieStore = cookies();
+ const token = cookieStore.get('token')?.value;
+ let existingUser;
+ if (token != null) {
+ let existingToken = await db
+ .selectFrom('tokens')
+ .where('tokens.id', '=', token)
+ .select('owner')
+ .executeTakeFirst();
+
+ if (existingToken != null) {
+ existingUser = await db
+ .selectFrom('users')
+ .where('users.id', '=', existingToken.owner)
+ .selectAll()
+ .executeTakeFirst();
+ }
+ }
+
const curUser = params.user;
if (curUser == null) return notFound();
@@ -63,6 +83,13 @@ export default async function Home({
{`${user.username}@${user.instance}`}
{user.banned ? <>BANNED - > : <>>}{user.admin ? <>ADMIN - > : <>>}Joined {new Date(parseInt(user.joined)).toDateString()}
{user.url}
+
+
+
Jams
{jams.map(async (jam:JSONJamTable) => {
const started = Date.now() >= parseInt(jam.date_start);