kjewfjnklwvnkldwvnklvwbnklwfb
This commit is contained in:
parent
86e593eb4c
commit
2a512ee545
13 changed files with 330 additions and 14 deletions
|
@ -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 (
|
||||||
|
<form onSubmit={formik.handleSubmit}>
|
||||||
|
<div>
|
||||||
|
<p><label htmlFor="submit">Are you sure?</label></p>
|
||||||
|
<input id="submit" name="submit" type="submit" value="Delete" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
67
src/app/jams/(manip)/delete/user/[userid]/page.tsx
Normal file
67
src/app/jams/(manip)/delete/user/[userid]/page.tsx
Normal file
|
@ -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 (
|
||||||
|
<MainLayout currentPage="/jams/" title="Edit User" subtitle="Jams" backButton>
|
||||||
|
<h1>Can't edit this user</h1>
|
||||||
|
<p>You are not this user</p>
|
||||||
|
</MainLayout>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MainLayout currentPage="/jams/" title="Edit User" subtitle="Jams" backButton>
|
||||||
|
<p>Deleting user <a href={`/jams/user/${editingUser.id}`}>{editingUser.username}@{editingUser.instance}</a></p>
|
||||||
|
<ConditionalNull condition={existingUser != null}>
|
||||||
|
<p><small>Logged in as <b>{existingUser?.username}@{existingUser?.instance}</b></small></p>
|
||||||
|
</ConditionalNull>
|
||||||
|
<Form userID={userid} />
|
||||||
|
</MainLayout>
|
||||||
|
)
|
||||||
|
}
|
78
src/app/jams/(manip)/edit/user/[userid]/components/form.tsx
Normal file
78
src/app/jams/(manip)/edit/user/[userid]/components/form.tsx
Normal file
|
@ -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 (
|
||||||
|
<form onSubmit={formik.handleSubmit}>
|
||||||
|
<div>
|
||||||
|
<p><label htmlFor="admin">admin</label></p>
|
||||||
|
<input
|
||||||
|
id="admin"
|
||||||
|
name="admin"
|
||||||
|
type="checkbox"
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
checked={formik.values.admin}
|
||||||
|
/>
|
||||||
|
<ConditionalNull condition={formik.touched.admin != null && formik.errors.admin != null}>
|
||||||
|
<p><small>Error: {formik.errors.admin}</small></p>
|
||||||
|
</ConditionalNull>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p><label htmlFor="banned">banned</label></p>
|
||||||
|
<input
|
||||||
|
id="banned"
|
||||||
|
name="banned"
|
||||||
|
type="checkbox"
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
checked={formik.values.banned}
|
||||||
|
/>
|
||||||
|
<ConditionalNull condition={formik.touched.banned != null && formik.errors.banned != null}>
|
||||||
|
<p><small>Error: {formik.errors.banned}</small></p>
|
||||||
|
</ConditionalNull>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p><label htmlFor="submit">Done?</label></p>
|
||||||
|
<input id="submit" name="submit" type="submit" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
67
src/app/jams/(manip)/edit/user/[userid]/page.tsx
Normal file
67
src/app/jams/(manip)/edit/user/[userid]/page.tsx
Normal file
|
@ -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 (
|
||||||
|
<MainLayout currentPage="/jams/" title="Edit User" subtitle="Jams" backButton>
|
||||||
|
<h1>Can't edit this user</h1>
|
||||||
|
<p>You are not an admin</p>
|
||||||
|
</MainLayout>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MainLayout currentPage="/jams/" title="Edit User" subtitle="Jams" backButton>
|
||||||
|
<p>Editing user <a href={`/jams/user/${editingUser.id}`}>{editingUser.username}@{editingUser.instance}</a></p>
|
||||||
|
<ConditionalNull condition={existingUser != null}>
|
||||||
|
<p><small>Logged in as <b>{existingUser?.username}@{existingUser?.instance}</b></small></p>
|
||||||
|
</ConditionalNull>
|
||||||
|
<Form userID={userid} preset={editingUser} />
|
||||||
|
</MainLayout>
|
||||||
|
)
|
||||||
|
}
|
|
@ -71,13 +71,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {content:st
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.judgement;
|
const id = params.judgement;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
@ -169,13 +173,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {content:s
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.judgement;
|
const id = params.judgement;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
|
|
@ -70,13 +70,17 @@ export async function POST(request: NextRequest, {params}: {params: {content: st
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select('id')
|
.select(['id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
body = await request.json();
|
body = await request.json();
|
||||||
|
|
|
@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {content:st
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.content;
|
const id = params.content;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
@ -126,13 +130,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {content:s
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.content;
|
const id = params.content;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
|
|
@ -75,13 +75,17 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select('id')
|
.select(['id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
body = await request.json();
|
body = await request.json();
|
||||||
|
|
|
@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {jam:string
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.jam;
|
const id = params.jam;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
@ -127,13 +131,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {jam:strin
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const id = params.jam;
|
const id = params.jam;
|
||||||
|
|
||||||
if (id == null) return new Response('', {
|
if (id == null) return new Response('', {
|
||||||
|
|
|
@ -41,13 +41,17 @@ export async function POST(request: NextRequest) {
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
if (!existingUser.admin) return new Response('you are NOT that guy.', {
|
if (!existingUser.admin) return new Response('you are NOT that guy.', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,13 +42,17 @@ export async function PATCH(request: NextRequest, {params}: {params: {user:strin
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const name = params.user;
|
const name = params.user;
|
||||||
|
|
||||||
if (name == null) return new Response('', {
|
if (name == null) return new Response('', {
|
||||||
|
@ -86,9 +90,9 @@ export async function PATCH(request: NextRequest, {params}: {params: {user:strin
|
||||||
let res;
|
let res;
|
||||||
try {
|
try {
|
||||||
res = await db
|
res = await db
|
||||||
.updateTable('jams')
|
.updateTable('users')
|
||||||
.set(newBody)
|
.set(newBody)
|
||||||
.where('id', '=', updatingUser.id)
|
.where('users.id', '=', updatingUser.id)
|
||||||
.executeTakeFirstOrThrow();
|
.executeTakeFirstOrThrow();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return new Response('', {
|
return new Response('', {
|
||||||
|
@ -123,13 +127,17 @@ export async function DELETE(request: NextRequest, {params}: {params: {user:stri
|
||||||
let existingUser = await db
|
let existingUser = await db
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.id', '=', existingToken.owner)
|
.where('users.id', '=', existingToken.owner)
|
||||||
.select(['admin', 'id'])
|
.select(['admin', 'id', 'banned'])
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (existingUser == null) return new Response('', {
|
if (existingUser == null) return new Response('', {
|
||||||
status: 401
|
status: 401
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (existingUser.banned) return new Response('U banned motherfucka!', {
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
|
||||||
const name = params.user;
|
const name = params.user;
|
||||||
|
|
||||||
if (name == null) return new Response('', {
|
if (name == null) return new Response('', {
|
||||||
|
|
|
@ -21,6 +21,26 @@ export default async function Home({
|
||||||
}) {
|
}) {
|
||||||
const curDate = Date.now();
|
const curDate = Date.now();
|
||||||
const curPage = parseInt(searchParams?.until) || curDate;
|
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;
|
const curUser = params.user;
|
||||||
|
|
||||||
if (curUser == null) return notFound();
|
if (curUser == null) return notFound();
|
||||||
|
@ -63,6 +83,13 @@ export default async function Home({
|
||||||
<h1>{`${user.username}@${user.instance}`}</h1>
|
<h1>{`${user.username}@${user.instance}`}</h1>
|
||||||
<p><small>{user.banned ? <><b>BANNED</b> - </> : <></>}{user.admin ? <><b>ADMIN</b> - </> : <></>}Joined {new Date(parseInt(user.joined)).toDateString()}</small></p>
|
<p><small>{user.banned ? <><b>BANNED</b> - </> : <></>}{user.admin ? <><b>ADMIN</b> - </> : <></>}Joined {new Date(parseInt(user.joined)).toDateString()}</small></p>
|
||||||
<p><a href={user.url} target="_blank">{user.url}</a></p>
|
<p><a href={user.url} target="_blank">{user.url}</a></p>
|
||||||
|
<ConditionalNull condition={existingUser != null}>
|
||||||
|
<div>
|
||||||
|
<ConditionalNull condition={existingUser?.admin == true}><p><b>You have the ability to modify this user.</b></p></ConditionalNull>
|
||||||
|
<ConditionalNull condition={existingUser?.admin == true}><p><a href={`/jams/edit/user/${user.id}`}>Edit user</a></p></ConditionalNull>
|
||||||
|
<ConditionalNull condition={existingUser?.admin || existingUser?.id == user.id}><p><a href={`/jams/delete/user/${user.id}`}>Delete user</a></p></ConditionalNull>
|
||||||
|
</div>
|
||||||
|
</ConditionalNull>
|
||||||
<h1>Jams</h1>
|
<h1>Jams</h1>
|
||||||
{jams.map(async (jam:JSONJamTable) => {
|
{jams.map(async (jam:JSONJamTable) => {
|
||||||
const started = Date.now() >= parseInt(jam.date_start);
|
const started = Date.now() >= parseInt(jam.date_start);
|
||||||
|
|
Loading…
Reference in a new issue