aboutsummaryrefslogtreecommitdiff
path: root/src/handler/user.ts
blob: e194008881956abbf30dd1edd069aada97c45aeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { HandlerFunc, Context } from "https://deno.land/x/abc@master/mod.ts";
import db, {loginData} from "../db/user.ts";

export const index: HandlerFunc = async (c: Context) => c.params.name;
export const register: HandlerFunc = async (c: Context) => {
    const { username, email, password } = await c.body();
    const success = await db.createUser(email, username, password);
    // TODO: Send email
    return {success};
};
export const login: HandlerFunc = async (c: Context) => {
    const { username, password } = await c.body();
    const data: loginData = await db.login(username, password);
    if (data.success) {
        c.setCookie({
            name: "uid",
            value: data.uid!.toString(),
        });
        c.setCookie({
            name: "verification",
            value: data.verification!,
        })
    }
    return {"success": data.success};
}