Back

Version 0

11/11/2024
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
import { sqlite } from "https://esm.town/v/std/sqlite";

export default async function(req: Request): Promise<Response> {
const TABLE_NAME = "lab_login_users_with_times";
const body = await req.json();
const { username, password, type, target } = body;
const tpUserQuery = await sqlite.execute({
sql: `SELECT * FROM ${TABLE_NAME} WHERE username = ?`,
args: ["TodePond"],
});

if (tpUserQuery.rows.length === 0) {
return new Response(JSON.stringify({ error: "admin user not found" }), { status: 404 });
}

const tpUser = tpUserQuery.rows[0];
const storedPassword = tpUser[2];
const passwordMatch = await bcrypt.compare(password, storedPassword);

if (!passwordMatch) {
return new Response(JSON.stringify({ error: "wrong admin password" }), { status: 401 });
}

if (type === "kick" && target === "name") {
if (username === "TodePond") {
return new Response(JSON.stringify({ error: "cannot kick admin" }), { status: 400 });
}
// delete the user
await sqlite.execute({
sql: `DELETE FROM ${TABLE_NAME} WHERE username = ?`,
args: [username],
});
} else if (type === "kick" && target === "status") {
// set the user's status to "user's status was removed by admin"
await sqlite.execute({
evol-labloginbanuser.web.val.run
Updated: November 11, 2024