Code
HTTP
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
import { email } from "https://esm.town/v/std/email";
import { sqlite } from "https://esm.town/v/std/sqlite";
export default async function(req: Request): Promise<Response> {
const body = await req.json();
let { username, password } = body;
if (!username || !password) {
return new Response(JSON.stringify({ error: "Missing username or password" }), { status: 400 });
}
if (password.length > 50) {
return new Response(JSON.stringify({ error: "Password too long" }), { status: 400 });
}
if (username.length > 50) {
return new Response(JSON.stringify({ error: "Username too long" }), { status: 400 });
}
const TABLE_NAME = "todepond_lab_login_users_with_times";
// Create users table if it doesn't exist
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
status TEXT DEFAULT 'hello i am new',
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
banned INTEGER DEFAULT 0
)
`);
const existingUser = await sqlite.execute({
sql: `SELECT * FROM ${TABLE_NAME} WHERE username = ?`,
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
netux-todepondlablogin.web.val.run
Updated: August 30, 2024